我有一个ASP MVC应用程序,带有一些看似简单的代码来保存和检索cookie但由于某种原因它们不会持久存在.控制器中的代码是:
if (System.Web.HttpContext.Current.Response.Cookies["CountryPreference"] == null)
{
HttpCookie cookie = new HttpCookie("CountryPreference");
cookie.Value = country;
cookie.Expires = DateTime.Now.AddYears(1);
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
}
Run Code Online (Sandbox Code Playgroud)
并再次加载它:
if (System.Web.HttpContext.Current.Request.Cookies["CountryPreference"] != null)
{
System.Web.HttpContext.Current.Request.Cookies["CountryPreference"].Expires = DateTime.Now.AddYears(1);
data.Country = System.Web.HttpContext.Current.Request.Cookies["CountryPreference"].Value;
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,cookie总是为空?
我们有一个面向外部的应用程序,由外部安全公司进行渗透测试.应用程序已在ASP.NET MVC4上开发并在IIS8/Windows 2012 Server上运行.
报告的漏洞之一是ASPXAUTH不安全.当我检查cookie检查器时,有一些带有安全标志的cookie.但ASPXAUTH不是其中之一.
我做了一些研究,并在web.config上设置了下面这些标志
<forms loginUrl="~/Account/Login" timeout="2880" requireSSL="" name="AppName" />
Run Code Online (Sandbox Code Playgroud)
和
<httpCookies httpOnlyCookies="true" requireSSL="true" />
Run Code Online (Sandbox Code Playgroud)
尽管有这些设置,但身份验证cookie未标记为安全.我认为这些标志应该足以将应用程序cookie标记为安全,但是还有一些其他cookie也没有标记为安全.我不太关心它们,因为它们不包含任何敏感信息.但我想将ASPXAUTH标记为安全.
我的问题是,
谢谢.