我正在使用 OWIN 通过 Facebook 进行身份验证:http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on
当用户尝试访问未经身份验证的页面时,我希望能够重定向到特定的登录页面。
就目前而言,当我用 [Authorize]
装饰一个 Action 时,我从 IIS 收到 401 错误。
如果我使用表单例份验证,我会在我的 web.config 中有这个:
<authentication>
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
我可以用 OWIN 做一些类似的事情,还是我需要创建一个自定义的 Authorize 属性?
最佳答案
您可以在配置 cookie 身份验证时配置登录页面:
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
关于asp.net - 使用 OWIN 重定向到登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21079412/