0

This might be a possible duplicate, but as I none of the answers were working for me from those portals, I'm posting the question again.

I have a website and when I'm trying to test the session data within this website by giving two different domain names in the URL.

I'm attaching screenshots for brief explanation. enter image description here

When I log in to the URL ssfound.com, the session is saved and my login details are displayed.

When I open www.ssfound.com then the session is unable to get htese login details.

I searched in the internet and found few solutions but none of them are working. I tested after adding it into config file , but below doesn't work

<httpCookies domain=".ssfound.com"/>

<httpCookies domain="ssfound.com"/>

I even tried <sessionstate cookieless="true"/> and mode = InProc but neither these work.

please don't mark it as duplicate, because I tried the above solutions in from the stackoverflow community & they didn't work from me.

ashveli
  • 248
  • 6
  • 28

1 Answers1

1

Your sites ssfound.com and www.ssfound.com are considered as two different sites, similar to http and https.

Choose between non-www or www and always redirect users to your desired url, this also help you in terms of SEO, analytics, inbound links, etc.

You can use below c# code (in global file) to convert non www site users to www site.

protected void Application_BeginRequest (object sender, EventArgs e)
{
   if (!Request.Url.Host.StartsWith ("www") && !Request.Url.IsLoopback)
   {
      UriBuilder builder = new UriBuilder (Request.Url);
      builder.Host = "www." + Request.Url.Host;
      Response.StatusCode = 301;
      Response.AddHeader ("Location", builder.ToString ());
      Response.End ();
   }
}
Nag Bandla
  • 56
  • 2
  • 13
  • thank you for the solution, this is working. But, I've to check if this is affecting the existing functionality or not. – ashveli Jul 03 '17 at 14:53