Server.Transfer and Session

P

PJ

I'm trying to set up a front controller pattern in my web application but
having Session issues when using Server.Transfer. I have created a web
handler that processes requests for .ptv files. I have enabled default
documents for the web app and set the top entry to default.ptv and have
created blank files in all of the directories named default.ptv. The client
initially requests a page with a url like www.domain.com/admin/ and the
handler handles the request and calls context.Server.Transfer to an actual
..aspx page. However, the first call to Session in the page throws an
exception: Session state can only be used when enableSessionState is set to
true, either in a configuration file or in the Page directive.

I do not receive this error if I use context.Response.Redirect or if I
access the page directly.

The MSDN article (
http://msdn.microsoft.com/architect...s/dnpatterns/html/ImpFrontControllerInASP.asp )
on this pattern uses Server.Transfer, but the web handler is set up to
handle .aspx pages. One of the benefits I derive from the use of this
pattern is the ability to decouple the url navigation from actual .aspx
pages, so I would rather not do that.

What is the cause of this expection? Can I not use Session for non .aspx
pages even if I have a web handler to process these requests?

TIA~
PJ
 
R

Rick Strahl [MVP]

PJ,

Did you enable Session state in your handler? It's not automatic.

If you're using a Handler, you have to enable Session state by implmenting
one of these interfaces:

public class NewHandler : IHttpHandler, IRequiresSessionState

IRequiresReadOnlySessionState.

Hope this helps,

+++ Rick --


--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web


PJ said:
I'm trying to set up a front controller pattern in my web application but
having Session issues when using Server.Transfer. I have created a web
handler that processes requests for .ptv files. I have enabled default
documents for the web app and set the top entry to default.ptv and have
created blank files in all of the directories named default.ptv. The client
initially requests a page with a url like www.domain.com/admin/ and the
handler handles the request and calls context.Server.Transfer to an actual
.aspx page. However, the first call to Session in the page throws an
exception: Session state can only be used when enableSessionState is set to
true, either in a configuration file or in the Page directive.

I do not receive this error if I use context.Response.Redirect or if I
access the page directly.

The MSDN article (
http://msdn.microsoft.com/architect...s/dnpatterns/html/ImpFrontControllerInASP.asp )
 
P

PJ

That was it...thank you.

Rick Strahl said:
PJ,

Did you enable Session state in your handler? It's not automatic.

If you're using a Handler, you have to enable Session state by implmenting
one of these interfaces:

public class NewHandler : IHttpHandler, IRequiresSessionState

IRequiresReadOnlySessionState.

Hope this helps,

+++ Rick --


--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
http://msdn.microsoft.com/architect...s/dnpatterns/html/ImpFrontControllerInASP.asp )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top