I have included the below lines of codes in my Web.Config
and Glbal.asax.cs
files, but still when I use developer tools in the browser I the secure flags were not set for the below cookies. Also Configured SSLSettings in my IIS (selected checkbox requireSSL).
I would like to set the secure attribute to all cookies, not only to received but also to sent cookies.
In Web.config
:
<httpCookies requireSSL="true"/>
In Global.asax.cs
:
protected void Application_EndRequest(object sender, EventArgs e)
{
if (Request.IsSecureConnection == true && HttpContext.Current.Request.Url.Scheme == "https")
{
Request.Cookies["ASP.NET_SessionID"].Secure = true;
if (Request.Cookies.Count > 0)
{
foreach (string s in Request.Cookies.AllKeys)
{
Request.Cookies[s].Secure = true;
}
}
Response.Cookies["ASP.NET_SessionID"].Secure = true;
if (Response.Cookies.Count > 0)
{
foreach (string s in Response.Cookies.AllKeys)
{
Response.Cookies[s].Secure = true;
}
}
}
}
Then I have hosted my application on IIS 7.5 on my local machine. And enabled RequireSSL option in SSL Settings. When I click Browse *.443(https), I could see localhost running with HTTPS but when I check cookie attributes in the browser, the secure flag is not set.
Am I missing any configuration here?