使用OWIN重定向到登录页面

Mis*_*pic 5 asp.net asp.net-mvc owin

我正在使用OWIN通过以下方式向Facebook进行身份验证:http : //www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2和OpenID登录

我希望能够在用户未经身份验证的情况下尝试访问页面时重定向到特定的登录页面。

就目前而言,当我用修饰动作时[Authorize],我从IIS收到401错误。

如果我使用表单身份验证,则可以在web.config中使用它:

<authentication>
  <forms loginUrl="~/Account/Login" timeout="2880" />      
</authentication>
Run Code Online (Sandbox Code Playgroud)

我可以使用OWIN做类似的事情,还是需要创建自定义的Authorize属性?

Hao*_*ung 5

您可以在配置cookie身份验证时配置登录页面:

        app.UseCookieAuthentication(new CookieAuthenticationOptions {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
Run Code Online (Sandbox Code Playgroud)