2017-09-10 90 views
1

在ASP.NET核心2.0中使用http.sys作爲web服務器時,無法啓用匿名和Windows身份驗證工作時遇到問題。當我在IIS中託管但拒絕在http.sys服務器中工作時,它工作正常。 HomeController上的方法標籤[Authorize]Windows操作失敗,HTTP 500並且從不提示進行身份驗證。如何在ASP.NET Core 2.0中同時使用匿名和Windows身份驗證

的Program.cs

.UseHttpSys(options => 
    { 
     options.Authentication.Schemes = AuthenticationSchemes.Negotiate | 
    AuthenticationSchemes.NTLM; 
     options.Authentication.AllowAnonymous = true; 
     options.UrlPrefixes.Add("http://localhost:5000"); 
    }) 

HomeController.cs

[Authorize] 
    public class HomeController : Controller 
    { 
     [Authorize] 
     public IActionResult Windows() 
     { 
      return Content ("You are " + User.Identity.Name + "; Authentication Type:" + User.Identity.AuthenticationType); 
     } 

     [AllowAnonymous] 
     public IActionResult Anonymous() 
     { 
      return Content ("You are " + User.Identity.Name + "; Authentication Type:" + User.Identity.AuthenticationType);; 
     } 
    } 

異常

An unhandled exception occurred while processing the request. 

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. 
Microsoft.AspNetCore.Authentication.AuthenticationService+<ChallengeAsync>d__11.MoveNext() 
+0

當您收到一個500錯誤,你應該總是張貼的確切異常消息,是怎麼回事的人應該幫助你? – Tseng

+0

增加了例外。 –

回答

相關問題