我想保护我的cookie,我读了ASP.NET_SessionId cookie的“HTTPOnly”和“Secure” cookie标志。
我在VS中创建新的asp.net项目。在Inspectors中的 fiddler 中-> raw我有:
Cookie: DXCurrentThemeMVC=Office2010Black; ASP.NET_SessionId=1gq0t1mi234xyljqnxrzbqfx
然后我修改web.config:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpCookies httpOnlyCookies="true" requireSSL="true"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" requireSSL="true" />
</authentication>
但是在 fiddler 中相同的数据
Cookie: DXCurrentThemeMVC=Office2010Black; ASP.NET_SessionId=1gq0t1mi234xyljqnxrzbqfx
我想当我添加
<httpCookies httpOnlyCookies="true" requireSSL="true"/>
我看不到 fiddler 中的cookie,否则cookie将被加密。这是正确的结果吗?还是我在某处有错误?编辑
以及为什么我看不到 fiddler
Set-Cookie: ASP.NET_SessionId=ig2fac55; path=/; secure; HttpOnly
但是只有cookie没有设置,并且安全,并且在Firebug中也只有HttpOnly,我看到了相同的结果
EDIT2
似乎我发现了我的问题:我在iis上托管应用程序并在Firebug中寻找cookie,并且我有带有安全和httpOnly标志的cookie:
ASP.NET_SessionId=98sfd90sdf89sd0f80s8; path=/; secure; HttpOnly
最佳答案
看一下MSDN中的httpCookies Element session 。
httpOnlyCookies 设置响应 header 中的HttpOnly标志。
请参阅Protecting Your Cookies: HttpOnly文章。
requireSSL 强制cookie通过安全 channel 进行传输,因此不会删除它,并且会在传输过程中对其进行加密。
关于asp.net安全cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8852194/