In my website i have implemented custom session values. In which, on log on i set the session value to some object. This object is used to extract user specific data from db.
now the problem is If user logs in with : test1.somesite.com and logs off and again logs in with: test2.somesite.com that user is still receiving the data from object specific to test1.somesite.com.
the point is whichever site user frist logs in with the second time if he logs in with anathor subdomain he is always getting the data from previous sub domain login.
on log out from specific domain i cleared all the sessions(tried everything): by putting HttpContext.session["UserDetail"] = null;, HttpContext.Session.Abandon() and also HttpContext.Session.Clear();
i found out the solution it was not related something to session. But i also learned something from this problem. For all ASP.NET MVC programmers out there. please notice: if u create a subdomain by url rewriting in asp.net mvc, browser will treat different
subdomain as different websites. So browser is going to store a cookie for each subdomain.
For example: if you have
www.somesite.com and it's subdomain test1.somesite.com and test2.somesite.com. If u visit each of the above ur, each url will have their own corresponding cookies
and same goes for sessions. different urls different asp.net sessions and cookies.
now about my problem, i used static class to get the url from the address bar, that's what(static class) created the problem. first i visited test1.somesite.com, and retrieved the url using the static class, and from that url i displayed the user data. i don't
know but there was something with this static thing, it cached this site address somewhere in memory or server i don't know, if you guys know something about this plesae let me know. Now, after logging out with test1.somesite.com and again logging in with
test2.someisite.com, i again called the same function to access the url, but it gave me the url of the site i visited last time, that's the reason why used to get the contents of the site i visited last time than the current one, and everything displayed to
the user is always associated with the subdomain.
After removing the static thing and accessing the url using class instance, everything worked well.
If you guys have more information, about this static thing regarding what is said, please let me know.
nccsbim071
Member
24 Points
44 Posts
ASP.NET MVC Session across subdomains
Mar 23, 2010 01:02 PM|LINK
Hi,
In my website i have implemented custom session values. In which, on log on i set the session value to some object. This object is used to extract user specific data from db.
now the problem is If user logs in with : test1.somesite.com and logs off and again logs in with: test2.somesite.com that user is still receiving the data from object specific to test1.somesite.com.
the point is whichever site user frist logs in with the second time if he logs in with anathor subdomain he is always getting the data from previous sub domain login.
on log out from specific domain i cleared all the sessions(tried everything): by putting HttpContext.session["UserDetail"] = null;, HttpContext.Session.Abandon() and also HttpContext.Session.Clear();
but nothing seems to work
any help please
asp.net mvc session subdomains
ignatandrei
All-Star
134832 Points
21599 Posts
Moderator
MVP
Re: ASP.NET MVC Session across subdomains
Mar 23, 2010 03:01 PM|LINK
I do not understand what is working and what is not working .
However, for sharing session data, you can use
1. Session in Sql Server (http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ASPNET/sharing-asp-net-session-state-between-we)
2. Single Singnon model : http://msdn.microsoft.com/en-us/library/ms972971.aspx
3. cookie : http://mgrzyb.blogspot.com/2007/12/aspnet-and-subdomains.html
I do not know yet if 1 it works with MVC, but I assume yes.
thangchung
Participant
1048 Points
167 Posts
Re: ASP.NET MVC Session across subdomains
Mar 23, 2010 04:00 PM|LINK
Thanks ignatandrei for replying. Three method that you suggest very good!
Simple is better...
My Blog - My MSDN codePlease mark the replies as answers if they help
nccsbim071
Member
24 Points
44 Posts
Re: ASP.NET MVC Session across subdomains
Mar 26, 2010 04:20 AM|LINK
i found out the solution it was not related something to session. But i also learned something from this problem. For all ASP.NET MVC programmers out there. please notice: if u create a subdomain by url rewriting in asp.net mvc, browser will treat different subdomain as different websites. So browser is going to store a cookie for each subdomain.
For example: if you have www.somesite.com and it's subdomain test1.somesite.com and test2.somesite.com. If u visit each of the above ur, each url will have their own corresponding cookies
and same goes for sessions. different urls different asp.net sessions and cookies.
now about my problem, i used static class to get the url from the address bar, that's what(static class) created the problem. first i visited test1.somesite.com, and retrieved the url using the static class, and from that url i displayed the user data. i don't know but there was something with this static thing, it cached this site address somewhere in memory or server i don't know, if you guys know something about this plesae let me know. Now, after logging out with test1.somesite.com and again logging in with test2.someisite.com, i again called the same function to access the url, but it gave me the url of the site i visited last time, that's the reason why used to get the contents of the site i visited last time than the current one, and everything displayed to the user is always associated with the subdomain.
After removing the static thing and accessing the url using class instance, everything worked well.
If you guys have more information, about this static thing regarding what is said, please let me know.
Anyways,
thanks to you all
saintr
Member
18 Points
5 Posts
Re: ASP.NET MVC Session across subdomains
Mar 26, 2010 05:34 PM|LINK
>Use this on your web.config, it works well for me.