Turn off Session State for selected files in ASP.Net

I have an existing ASP.Net web application using Framework 2.0 and Visual Studio 2005. I want to add some web service files to the main web application folder (to add additional access to the functionality in the web application's classes via web services as well as the web pages). This would be easy EXCEPT that the web app is using SQL Server Session State. The web services, which don't need any kind of sessions state, are throwing errors due to session state. If I turn off session state, the web services run fine.

Is there any way to turn off sesson state for individual files in an ASP.Net web application that uses session state overall?

Thanks.
LVL 1
psyche6Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
The webmethod attribute provides EnableSession property which you can set to false and session would not be available to webservice

Check this link

http://msdn.microsoft.com/en-us/library/byxd99hx(VS.71).aspx#vbtskusingwebmethodattributeenablesession
0
psyche6Author Commented:
Thanks, SriVaddadi, for at least partial answer. It turns out that Session State is already disabled for ASP.Web services by default, but can be enabled if needed by the webmethod attribute mentioned.

I have tested this by monitoring the SQL Server login used for session state. SQL Server does not see a login when a web service in the web app is called, and does see a login when a web page in the web app is called. I also tested mis-configuring the SQL Server session state login password - the web service continued to run OK while the web page blew up.

So where does the problem come from?

It turns out that web services live comfortably in a web app that uses SQL Server Session State AS LONG AS the cookieless attribute of the sessionState element in the web.config file is NOT set to 'AutoDetect'. Either 'UseCookies' or 'UseUri' is OK. When the setting is AutoDetect, the follow response error is returned:

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fNewVector%2fBASFService.asmx%3fAspxAutoDetectCookieSupport%3d1">here</a>.</h2>
</body></html>

with an HTTP response code 302 (redirection).

So, apparently, ASP.Net does autodetection of the browser's cookie capability with a redirection mechanism which occurs when first browsing to the web site (regardless of the resource requested since I proved that a web service won't initiate session state), and the .Net web reference (and probably any standard SOAP tool) can't handle redirection and throws an error.

The nice thing about this is that I now know I can mix web services and web pages in the same ASP.Net web app that uses SQL Server Session State and the web services will not needlessly create wasteful Session State connections to SQL Server.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.