加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 在mvc 5和web api 2之间共享owin cookie身份验证

发布时间:2020-12-16 09:41:14 所属栏目:asp.Net 来源:网络整理
导读:我有一个使用web api 2,api的mvc 5应用程序. MVC应用程序使用owin cookie身份验证来验证用户,它工作正常.要求是,如果用户登录MVC应用程序,他还应该能够访问API中的安全方法. 当有asp.net表单auth时,我在API和MVC中使用相同的机器密钥来成功验证api中APP的用
我有一个使用web api 2,api的mvc 5应用程序.

MVC应用程序使用owin cookie身份验证来验证用户,它工作正常.要求是,如果用户登录MVC应用程序,他还应该能够访问API中的安全方法.

当有asp.net表单auth时,我在API和MVC中使用相同的机器密钥来成功验证api中APP的用户.但无法使用owin cookie身份验证.

以下是API和MVC应用程序的auth部分.

API

HttpConfiguration config = new HttpConfiguration();

        WebApiConfig.Register(config);
        app.UseWebApi(config);

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,});

MVC APP

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

两个项目中的web.configs都输入了相同的机器密钥.任何帮助将非常感激.

解决方法

以下是我的问题.它位于我的WebpiConfig.cs文件中的Register方法中.

config.SuppressDefaultHostAuthentication();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读