SharePoint 2010 Host header - Cookies issue
Hi all I have a web application created in SP2010 on port 80 and a host header with "MyServerName" was used while creating the webapplication through Central Administration. Host Name is reflected in IIS and a DNS entry is also made in the hosts file. I created a site collection and my site collection works fine. I have a visual web part hosted in my site collection. My web part just checks a cookie value using HttpContext.Current.Request.Cookies[MyCookie] if not creates a cookie and on subsequent request should get the value from cookie. But Mycookie is not found in cookie collection. We are using Windows authentication while creating the creating Web application. My webpart works fine when a webapplication does not have a host header. Can any one help me why the cookie is not found when there is a host header for the web application. below is sample code I am using. I tried cookie as secure and without secure too. Help would be higly appreciated. protected void Page_Load(object sender, EventArgs e) { string usrName = HttpContext.Current.User.Identity.Name.ToString(); if (HttpContext.Current.Request.Cookies[usrName.Remove(0, usrName.IndexOf("|") + 1)] != null) { lblMessage.Text = HttpContext.Current.Request.Cookies[usrName.Remove(0, usrName.IndexOf("|") + 1)].Value; } else { WriteCoookie(usrName); } } private void WriteCoookie(string usrName) { HttpCookie disclaimerCookie = new HttpCookie(usrName.Remove(0, usrName.IndexOf("|") + 1)); disclaimerCookie.Value = "Accepted Terms and Condition"; disclaimerCookie.Secure = true; disclaimerCookie.Expires = DateTime.MaxValue; disclaimerCookie.Domain = HttpContext.Current.Request.Url.Host; //disclaimerCookie.Path = "/"; // disclaimerCookie.Secure = true; HttpContext.Current.Response.Cookies.Add(disclaimerCookie); //HttpContext.Current.Response.Cookies.Set(disclaimerCookie); //HttpContext.Current.Response.Cookies[this.UserName].Secure = true; } }
January 28th, 2011 2:37am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics