2015-05-02 80 views
2

asp.net 5 MVC 6,視覺工作室2015 RC爲什麼使用UseCookieAuthentication會導致異常?

爲什麼這個代碼導致異常當我運行在(調試/釋放)應用

app.UseCookieAuthentication(options => 
{ 
     options.AuthenticationType = "Cookies"; 
     options.LoginPath = new PathString("/Action/Login"); 
}); 

System.IO.FileNotFoundException

無法加載文件或程序集Microsoft.Framework.Logging.ILoggerFactory,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null或它們的某個依賴項。找不到指定的文件。

我nugets包:

"Microsoft.Framework.Logging": "1.0.0-beta4", 
"Microsoft.Framework.Logging.Console": "1.0.0-beta4", 
"Microsoft.AspNet.Diagnostics": "1.0.0-beta4", 
"Microsoft.AspNet.Mvc": "6.0.0-beta4", 
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta4", 
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4", 
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4", 
"Microsoft.AspNet.StaticFiles": "1.0.0-beta4", 
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta4", 
"Microsoft.AspNet.Security.Cookies": "1.0.0-beta3", 
"Microsoft.AspNet.Security": "1.0.0-beta3", 
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", 
"Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta4", 
"Microsoft.Framework.DependencyInjection": "1.0.0-beta4", 
"Microsoft.Framework.OptionsModel": "1.0.0-beta4", 
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta4", 
"Npgsql": "2.2.5" 

回答

4

刪除安全包和補充一點:

「Microsoft.AspNet.Authentication.Cookies」: 「1.0.0-BETA4」

和,登錄/註冊控制器

var claims = new List<Claim> {new Claim(ClaimTypes.Name, model.Username)};    
Context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies"))); 

beta5的轉發:

var claims = new List<Claim> {new Claim(ClaimTypes.Name, model.Username)};    
await Context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies"))); 
+0

我想這和它的編譯,但它似乎並沒有真正登錄我,[授權]保護的操作屬性仍然返回一個401這是爲你工作? – Tom

+0

app.UseCookieAuthentication(options => { options.AutomaticAuthentication = true; options.LoginPath = new PathString(「/ Account/Login」); }); – SrdTLT

+0

var claims = new List { new claim(ClaimTypes.Name,USERNAME) }; Context.Response.SignIn(「Cookies」,新ClaimsPrincipal(新ClaimsIdentity(聲明,「Cookies」)));這對我有用。 – SrdTLT

相關問題