在asp.net中的Owin多路径

时间:2016-10-26 22:26:02

标签: asp.net-mvc

我像Owin一样上课

public void ConfigureAuth(IAppBuilder app)
{


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

    });
}

然后我有另一个链接,如/distributor/Login

当我在没有登录的情况下去家乡经销商时,总是会重定向到members/login

如何配置我需要重定向到/distributor/login

由于

1 个答案:

答案 0 :(得分:0)

您可以尝试CookieAuthenticationProvider,但我没有测试您的方案

设置LoginPath = null CookieAuthenticationOptions.LoginPath

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = null,
   Provider = new CookieAuthenticationProvider { 
  OnApplyRedirect =  (context) =>
 {
   Uri defaultURI = Url.Action("Login", "members"); 
 //check for distributor in the request uri
 //Modify logic appropriately
 if(context.Request.Url.PathAndQuery.Contains("distributor"))
 {
  defaultURI = Url.Action("login", "distributor"); ;
  }

context.RedirectUri = defaultURI;
originalHandler.Invoke(context);
 };

});