Glenn Ferrie
Glenn Ferrie

Reputation: 10390

Configure anonymous access for static file from appsettings.json or startup.cs

I am writing an ASP.NET Core 5 app. There is an Azure configuration to prove you own an identity that required you to host an file at this location:

https://yoursite.com/.well-known/microsoft-identity-association.json

So I created a directory in the wwwroot folder of my project alongside 'css' and 'js' and name the file accordingly.

However the path is authorized, and I need to make it available with Anonymous Access.

In the ASP.NET classic (.NET Framework), we could use a <location href=".well-known"> element to configure settings specific to that server relative path.

Is there an equivalent in ASP.NET Core's appsettings.json, to allow anonymous access by path?

Upvotes: 1

Views: 510

Answers (1)

Glenn Ferrie
Glenn Ferrie

Reputation: 10390

Thanks to @jeremy-thompson ... here is my solution.

[AllowAnonymous]
[Route(".well-known/microsoft-identity-association.json")]
public IActionResult MSIdentityAssoc()
{
    return Json(new
    {
        associatedApplications = new[]
        {
            new { applicationId = Guid.Parse("xxxxxxxx-xxxx-xxxx-xxxx-xxxxyyyyzzzz") }
        }
    });
}

Upvotes: 1

Related Questions