0
我在登录页面实现了owin身份验证,但是我想在asp.net vnext(MVC6)中使用owin身份验证的中间件,因为我想在用户登录状态保持很长时间时重定向到默认(登录)页面。下面的代码是参考资料。如何在asp.net vnext(MVC 6)中创建/创建owin认证中间件?
var claims = new List<Claim>
{
new Claim("UserId",user.Id),
new Claim("UserName",user.UserName),
new Claim("Roles",user.UserRoles)
};
var ident = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie,user.UserName,user.UserRoles);
var authProp = new AuthenticationProperties() {IsPersistent=true,AllowRefresh=true,ExpiresUtc=System.DateTime.Now.AddMinutes(1).ToLocalTime(),RedirectUri="/Account/Login"};
IOwinContext owinContext = new OwinContext();
owinContext.Authentication.SignIn(authProp, ident);
在此先感谢。
谢谢你,分享你对问题的看法。但我希望用户凭证的中间件能够被mvc6应用程序的任何页面动态捕获,并且如果用户长时间登录,所以我想重定向默认页面意味着在mvc6中注销页面。 所以这是我在开发mvc6项目时遇到的问题。 如果你知道如何解决这个问题,请分享你的想法,我很欣赏你的想法。 – johnkhadka