Reputation: 565
When we created our server-side blazor app (ASP.NET Core Web App) initially we did not enable authentication. We would like to enable windows authentication now.
I created a test web app with windows authentication and tried adding missing bits into our existing web app. Below are the changes that I made:
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@code {
[CascadingParameter]
private Task<AuthenticationState> authenticationStateTask { get; set; }
private async Task LogUsername()
{
var authState = await authenticationStateTask;
var user = authState.User;
if (user.Identity.IsAuthenticated)
{
Console.WriteLine($"{user.Identity.Name} is authenticated.");
}
else
{
Console.WriteLine("The user is NOT authenticated.");
}
}
}
When I run the web app locally in Visual Studio 2019 preview, I am always ending up with an empty identity name. And, IsAuthenticated is always false. However, if I run the test web app locally, it gets the correct identity name.
Does anyone know what I am missing in my existing web app?
Thanks!
Upvotes: 10
Views: 11713
Reputation: 209
I have a Blazor Server project that has two possible debug start profiles
The web project itself XX.SD starts in the browser but the launch profile does not have an option for Windows Authentication. The IIS Express lauch profile however does have this option in the Properties page.
Upvotes: 4
Reputation: 11
Just Enable windows Authentication button : Project=>properties => Debug => web server settings
Upvotes: 1
Reputation: 565
Apparently, I missed checking the box for windows authentication under Project Properties > Debug tab.
Upvotes: 10