簡體   English   中英

如何在asp.net vnext(MVC 6)中制作/創建OWIN身份驗證中間件?

[英]How to make/create owin authentication middleware in asp.net vnext(MVC 6)?

我在登錄頁面中實現了owin身份驗證,但是我想在asp.net vnext(MVC6)中使用owin身份驗證的中間件,因為當用戶登錄狀態保持很長時間時,我想重定向到default(Login)頁面。以下代碼是參考。

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);

提前致謝。

如果您在用戶未登錄的情況下查找“默認登錄頁面”,則可以使用控制器上方的[Authorize]屬性。

namespace Demo.Controllers
{   
 [Authorize]
 public class DemoController : Controller
 {
  // Your Code
 }
}

這應該可以幫助您..!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM