【发布时间】:2013-11-22 17:51:43
【问题描述】:
我刚刚开始将 OWIN\Katana 用于 Web api 项目。它使用 Windows 身份验证。这似乎有效,但我的大多数集成测试都失败了。他们以前只是使用内存中的HttpServer,但我已经改为使用Microsoft.Owin.Testing.TestServer。我在我的测试设置中替换了这样的东西:
var config = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always };
config.EnableQuerySupport();
Server = new HttpServer(config);
MyConfigClass.Configure(config);
WebApiConfig.Register(config);
用更简单的:
TestServer = TestServer.Create<Startup>();
但是以前我可以将以下内容用于内存服务器的“假”身份验证:
Thread.CurrentPrincipal = new ClientRolePrincipal(new HttpListenerBasicIdentity(Username, Password));
这现在不起作用。对于所有请求,我都会收到以下信息:
System.Exception : {"Message":"Authorization has been denied for this request."}
如何使用 In-Memory OWIN 测试服务器进行身份验证或至少绕过身份验证?
【问题讨论】:
标签: asp.net authentication asp.net-web-api owin katana