【发布时间】:2018-04-08 04:50:36
【问题描述】:
我们正在运行一个经典的 ASP Web 应用程序,并希望它与新开发的 MVC 应用程序一起工作。我们想在 MVC 应用程序中利用经典 asp 应用程序的身份验证。
这个想法是当用户登录经典的asp应用程序时,它会发出一种auth cookie,cookie是用我们自己的方法加密的。 Cookie 将包含使用身份。
客户端然后浏览到 MVC 应用程序以及此身份验证 cookie。 MVC 应用程序将检查 cookie 是否存在并对其进行验证。使用它不会重定向到经典的 asp 登录页面。
所以我正在考虑自定义 OWIN cookie 身份验证以使用我自己的身份验证逻辑。我尝试实现 CookieAuthenicationProvider 但是我不知道将我的逻辑放在哪里。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
CookieName = ".classicauth",
CookieSecure = CookieSecureOption.SameAsRequest,
CookieHttpOnly = true,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = context => {
//?? where I can extract the cookie and validate it??
context.RejectIdentity();
return Task.FromResult<int>(0);
},
OnApplyRedirect = context => {
context.Response.Redirect("classic_asp_login_url");
}
}
});
CookieAuthenticationProvider 有一个 OnValidateIdentity,但它似乎不是提取 cookie 并对其进行验证的正确位置。
谢谢。 杰森。
【问题讨论】:
标签: asp.net asp.net-mvc authentication cookies owin