Reputation: 87
I've being facing a problem with redirection. I will explaining my problem into 2 cases
Case 1:
Redirection to <NotFound>
page never succeed. What am I missing here?
Case 2:
Redirection to Login
page succeed at local development but not when I deployed to IIS. Everything work like it should at local but when at server I'm facing error HTTP ERROR 500
. Below are the lines I've been tried so far.
I'm using a controller for authentication process, the redirection I've made at controller seems ok it redirect me to /home
after successful login also the logout process seems ok.
P/S: I created the BlankLayout.razor
in the folder Layout
Routes.razor
<CascadingAuthenticationState>
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" >
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
<NotFound>
<LayoutView Layout="typeof(Layout.BlankLayout)">
<p>There is nothing over here</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
RedirectToLogin
@inject NavigationManager NavigationManager
@attribute [AllowAnonymous]
@code {
protected override void OnInitialized()
{
NavigationManager.NavigateTo($"/login?returnUrl={Uri.EscapeDataString(NavigationManager.Uri)}", forceLoad: true);
}
}
Program.cs
builder.Services.AddAuthorization();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(x =>
{
x.LoginPath = "/login";
x.LogoutPath = "/auth/logout";
});
builder.Services.AddControllers();
builder.Services.AddScoped<CookieEvent>();
builder.Services.ConfigureApplicationCookie(x =>
{
x.EventsType = typeof(CookieEvent);
});
Upvotes: 1
Views: 907
Reputation: 22029
Steps to reproduce the issue.
Step 1 Create a brand new server and install IIS and asp.net core Hosting Bundle.
Step 2 Reproduce the issue.
Step 3 Download url rewrite here.( https://www.iis.net/downloads/microsoft/url-rewrite) and install it.
Step 4 Close the IIS Manager.
Step 5 Refresh the tab page in browser. The tab1 for comparing.
Upvotes: 1