我試圖運行由Windows身份驗證的IIS承載的OWIN/Katana應用程序,但無論我做什麼,我似乎都會得到未經過身份驗證的GenericPrincipal
,而不是相關的WindowsPrincipal
。如何在IIS中託管OWIN/Katana時獲取WindowsPrincipal?
我Startup.cs
:
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
WebApiConfig.Register(config);
app.UseWebApi(config);
}
}
我的控制器:
public class TestController : ApiController
{
[Authorize]
public string Get()
{
return "Test";
}
}
不必看着通過代碼的要求和調試,它看起來好像NTLM身份驗證成功的情況發生,但是當它到達WebAPI,委託人未通過身份驗證,因此它返回401,導致IIS再次嘗試執行Windows身份驗證。
Web.config文件片段:
<system.web>
<authentication mode="Windows" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
更新
看樣子WindowsPrincipal
並使其成爲我添加了一個虛擬中間件,但不進的WebAPI本身。看起來Katana正在改變管道的某一點。
向我們展示部分web.config – Dryadwoods
任何部分? – ChrisPatrick
你應該是這樣的: \t \t <授權> \t \t \t <拒絕用戶=/「?」> \t \t授權> \t \t <認證模式= 「窗口」/> 上午我糾正? –
Dryadwoods