//app.UseIdentity();
app.UseCookieAuthentication(options => {
//options.AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;// "MyCookieMiddlewareInstance";
options.LoginPath = new PathString("/Account/Unauthorized/");
options.AccessDeniedPath = new PathString("/Account/Forbidden/");
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
});
using System.Security.Claims;
using Microsoft.AspNet.Authentication.Cookies;
using Microsoft.AspNet.Identity;
public async Task<IActionResult> Login()
{
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, "Admin")); // value of this.User.GetUserName() or this.User.Identity.Name
claims.Add(new Claim(ClaimTypes.NameIdentifier, "10001")); // value of this.User.GetUserId();
claims.Add(new Claim("SelfDefined1", "value1"));
var ci = new System.Security.Claims.ClaimsIdentity(claims, IdentityCookieOptions.ApplicationCookieAuthenticationType);
var cp = new System.Security.Claims.ClaimsPrincipal(ci);
await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, cp );
return View("Index");
}
bool signed = this.User.IsSignedIn();
string userName = this.User.Identity.Name;
userName = this.User.GetUserName();
MVC6 OWin Microsoft Identity 自定义验证
原文:http://www.cnblogs.com/ybst/p/5138565.html