有在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