【发布时间】: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