【发布时间】:2016-05-18 17:58:21
【问题描述】:
我有一个现有的 mvc webapi 系统,它不使用身份验证或授权,我正在尝试添加 Windows 身份验证。我通过创建一个新的简化系统来解决这个问题,其中单个控制器只返回静态数据。
新系统设置为使用 Windows 身份验证,因此当我连接到 Application_AuthenticateRequest 时,HttpContext.Current.User 不为空,并且具有填充的 Identity 属性和正确的用户 WindowsPrincipal发送请求。
在现有系统中,当我修改 web.config 以匹配新(工作)系统时,所有传入的请求在 Application_AuthenticateRequest 中都有一个空的 HttpContext.Current.User。
我看到一篇帖子建议我使用Application_AuthorizeRequest 事件处理程序,因为它稍后会在管道中触发。正如预期的那样,HttpContext.Current.User 此时不为空,但是 Identity 属性设置为具有Anonymous 的模拟级别,并且重要的是未经过身份验证。
我假设我尝试添加身份验证的生产系统以某种方式配置为不使用模拟,但我的新概念验证系统是。因此,管道的 Authenticate 阶段正在向 HttpContext 添加一个匿名用户,这就是我在管道的 Authorize 阶段看到的。
我的问题是如何配置我的生产系统以使用模拟,以便我可以访问已发送请求的用户?
请注意,系统已部署到 Intranet,因此我只需要用户的 Windows 身份并提供足够的安全性。
我的网络配置包含以下内容:
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
<authentication mode="Windows" />
<identity impersonate="true" />
<httpModules>
</httpModules>
</system.web>
在两个系统(生产和 POC)中,我都尝试从两者中删除 <identity/> 元素,但它似乎没有任何效果。
在这个阶段,我只通过 VS2015 在 IISExpress 中托管
【问题讨论】:
标签: c# asp.net-mvc authentication asp.net-web-api