【问题标题】:Sharing owin cookie authentication between mvc 5 and web api 2在 mvc 5 和 web api 2 之间共享 owin cookie 身份验证
【发布时间】:2015-06-03 11:37:51
【问题描述】:

我有一个使用 web api 2、api 的 mvc 5 应用程序。

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

当有 asp.net forms auth 时,我在 API 和 MVC 中使用相同的机器密钥来成功地在 api 中对来自 APP 的用户进行身份验证。但无法使其与 owin cookie 身份验证一起使用。

以下是 API 和 MVC 应用程序的身份验证部分。

API

 HttpConfiguration config = new HttpConfiguration();

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

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

MVC 应用

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

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

【问题讨论】:

    标签: asp.net-mvc asp.net-web-api owin


    【解决方案1】:

    以下行对我来说是个问题。它在我的 WebpiConfig.cs 文件的 Register 方法中。

    config.SuppressDefaultHostAuthentication();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 2015-09-07
      • 2014-11-12
      相关资源
      最近更新 更多