重定向与OWIN到登录页面 [英] Redirect to login page with OWIN

查看:537
本文介绍了重定向与OWIN到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OWIN每Facebook的身份验证:<一href=\"http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on\" rel=\"nofollow\">http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on

I'm using OWIN to authenticate with Facebook per: http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on

我希望能够当用户尝试,而他们是未经验证的访问页面重定向到一个特定的登录页面。

I want to be able to redirect to a specific login page when a user attempts to visit a page while they are unauthenticated.

既然这样,当我与装饰动作[授权] ,我得到一个401错误从IIS。

As it stands, when I decorate an action with [Authorize], I get a 401 error from IIS.

如果我使用窗体身份验证,我会在这我的web.config:

If I was using Forms authentication, I would have this in my web.config:

<authentication>
  <forms loginUrl="~/Account/Login" timeout="2880" />      
</authentication>

有没有类似的东西我可以做OWIN,或者我需要创建一个自定义属性授权?

Is there something similar I can do with OWIN, or do I need to create a custom Authorize attribute?

推荐答案

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

You can configure the login page when you are configuring the cookie authentication:

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

这篇关于重定向与OWIN到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆