I have to set a cookie path attribute in the asp.net application. I am getting "" only path if I changed the session state .Please help me to how to change cookie path in the asp.net application
//web config
//global asax protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e) { // only apply session cookie persistence to requests requiring session information if (Context.Handleris IRequiresSessionState || Context.Handleris IReadOnlySessionState) { var sessionState = ConfigurationManager.GetSection("system.web/sessionState")as SessionStateSection; var cookieName = sessionState !=null && !string.IsNullOrEmpty(sessionState.CookieName) ? sessionState.CookieName :"ASP.NET_SessionId";
var timeout = sessionState !=null ? sessionState.Timeout : TimeSpan.FromMinutes(20);
// Ensure ASP.NET Session Cookies are accessible throughout the subdomains.
if (Request.Cookies[cookieName] !=null && Session !=null && Session.SessionID !=null)
{
Response.Cookies[cookieName].Value = Session.SessionID;
Response.Cookies[cookieName].Path = Request.ApplicationPath;
Response.Cookies[cookieName].Expires = DateTime.Now.Add(timeout);
}
}
}
you should Provide Default Path for your Cookie which is Server root. the Below Code snippet shows how to set Default Server Root path
so basically as your Code, you can do Following