?
Solved

ASP.NET - Change session cookie name from asp.net_sessionid

Posted on 2004-03-31
7
Medium Priority
?
4,687 Views
Last Modified: 2009-11-06
Hi,

I want to use the built in session management of ASP.NET, BUT I want the cookie name to be changed from asp.net_sessionid to something of my choosing.

Is there a way in the framework configuration or ASP.NET code that I can force the name of the session cookie from "asp.net_sessionid" to some other name?

Can it be done?

Thanks,

Mike
0
Comment
Question by:mchallis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 12

Expert Comment

by:dfiala13
ID: 10727267
No.  That is what it is named.  It is created by the SessionStateModule. If you could override this module then you could potentially rename it, but the class cannot be inherited.

You can, of course write your own class to based on IHttpModule to do your own session management and name your cookie anything you want, but that means you don't get to use the built-in session state features.
0
 

Author Comment

by:mchallis
ID: 10727734
Could I implement my own HttpModule / pipeline that renames my cookie to asp.net_sessionid on the way in and rename asp.net_sessionid the way out so that the browser deals with my cookie name but the framework sees the original name?

If this can be done, does anyone have any examples?
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10727756
You could potentially could, but one wonders why you would go through the trouble to rename a cookie.
0
 

Author Comment

by:mchallis
ID: 10727818
True, but humour me.

It is to do with an existing infrastructure (web load balancers, proxies and a web farm) that uses the session cookie to give "sticky" sessions.  But the session cookie it looks for has to be of a predined name (pre ASP.NET).

Therefore if I can rename the ASP.NET cookie, the users session gets tied to one web server and proxy, otherwise it bounces around on each request.

Cheers,


Mike
0
 
LVL 12

Accepted Solution

by:
dfiala13 earned 2000 total points
ID: 10727946
Ah, I see.
Why rename the cookie, why not just create a cookie in an HttpModule with the proper name and set its value to the value in the ASP.NET approved session cookie.

Here's a little background on how Session IDs work in ASP.NET (don't mind the ad and the classic ASP stuff)

http://builder.com.com/5100-6373-1044890.html

Here's a link to MS's example custom HttpModule,  which actually should get you close .  Instead of returning a message in Application_EndRequest  simply add on your cookie to the Response.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomhttpmodules.asp
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question