有在ASP.NET 5.0基于Cookie的身份验证的新的实现,这些例子可以在官方MicroSoft ASP.NET Security GitHub page
找到
首先,你将需要认证库添加作为依赖于你的project.json文件:
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
"Microsoft.AspNet.Mvc": "6.0.0-beta4",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
看行:
using Microsoft.AspNet.Authentication.Cookies;
和:
app.UseCookieAuthentication(options =>
{
options.AutomaticAuthentication = true;
});
app.Run(async context =>
{
if (string.IsNullOrEmpty(context.User.Identity.Name))
{
var user = new ClaimsPrincipal(new ClaimsIdentity(
new[]
{
new Claim(ClaimTypes.Name, "bob")
}
));
context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme,
user);
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer");
return;
}
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello old timer");
});
这应该在6 MVC的Web应用程序app.UseMvc()面前。 我希望这有助于?让我知道如果这不符合您的要求,我会尽力澄清任何要点:)
对此有何帮助?谢谢 – 2015-02-12 06:24:42
通过我们的电子邮件线程,这将很快* *很快*。多久会很快? *很快 :) – Eilon 2015-02-13 22:19:17