为什么httpRuntime targetFramework =" 4.5"禁用抓取.ASPXAUTH cookie?

时间:2015-09-15 20:41:07

标签: c# asp.net-mvc cookies asp.net-membership forms-authentication

当我的web.config具有以下httpRuntime时,我的控制器无法获取cookie .ASPXAUTH。它似乎能够抓取任何其他cookie,有或没有句点前缀。如果我删除以下行,它可以正常工作。

<httpRuntime targetFramework="4.5"/>

我使用以下内容获取Cookie。

HttpCookie authCookie = Request.Cookies[".ASPXAUTH"];

为什么我无法获取表单身份验证Cookie?

1 个答案:

答案 0 :(得分:3)

我有类似的问题 - 我的运行时4.5的应用程序无法读取由4.0运行的另一个/ login / app创建的.ASPXAUTH cookie,导致重定向循环。结果4.5介绍了一些可以通过在web.config中设置以下内容来启用的加密改进:

<强>原因:

<machineKey compatibilityMode="Framework45" />

or

<httpRuntime targetFramework="4.5" />

https://blogs.msdn.microsoft.com/webdev/2012/10/23/cryptographic-improvements-in-asp-net-4-5-pt-2/1

解决方案:在我的情况下(许多其他4.0应用依赖于Cookie)解决方案是切换我的新应用使用:

<machineKey compatibilityMode="Framework20SP1" validationKey="..shared with login app, along with decryptionKey etc...">

or

remove the <httpRuntime /> element

当然这只是一种解决方法,我将尽快将我的所有应用更新为更安全的4.5身份验证。