سؤال

In ASP.NET MVC 5 you specify the login path URL in method ConfigureAuth(...) which is called from Application_Start():

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login")
});

I need someway to specify the login path according to a localized route parameter.

One way I have in my mind is to redirect the user in Application_AuthenticateRequest() to the desired login page in case Request.IsAuthenticated is false. But I am not really sure whether this is a good idea or not.

هل كانت مفيدة؟

المحلول

Using OWIN, you can't assume the Application_AuthenticateRequest IIS programming model. You should assume OWIN's programming model.

Anyway, on the CookieAuthenticationOptions, there's a Provider property. On this there's a ApplyRedirect event you ca handle. In there you could alter the redirect URL.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top