Dynamic web pages using VirtualPathProvider

C

Charles Zhang

I am creating dynamic web pages according to the user inputs from a web
page.

For instance, a user typed in a text, I would want the text being the
source code of the dynamic page.

My question is: How could I access session variables from class that
derives from VirtualPathProvider or VirtualFile or the control values of
previous web page?

I could not use query string or cookies due to the amount of the data.

I am using HostingEnvironment to retrieve application path information.
I guess there are some similar global instance that I might be able to
use to retrieve information for the request.


Thanks

Charles Zhang
 
W

Walter Wang [MSFT]

Hi Charles,

The session is provided by the System.Web.SessionState.SessionStateModule
as one of the http modules pipeline. However, a VirtualPathProvider or
VirtualFile is called at page compilation stage, at which moment the
modules are not initialized yet. Therefore you will not be able to use
Session in VirtualPathProvider or VirtualFile.

Why not use HttpContext.Current.Items to pass the information? Normally
it's used to pass data between different http modules, but I think you can
also use it to pass data to the dynamic web page.

Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Charles Zhang

I think HttpContext.Current.Items will do the trick for me? However, how
could I deal with thread issue or do I need to worry about threading at all?

One thing I can think is to use a application variable flag to indicate
if some other session is trying to access HttpContext.Current.Items. I
guess you might know better ways.

Thanks
 
C

Charles Zhang

Just more details about what I am planning to do.

Each session will only have one item in HttpContext.Current.Items.
Therefore, the session ID will be the key for the item.

I embedded the session ID into the file name of dynamic page request so
that I can retrieve the session ID then retrieve the value I stored in
HttpContext.Current.Items.

A number of sessions might add new items, retrieve items from
HttpContext.Current.Items at the same time (Of course with different
keys), do I need to worry about concurrent access issue from different
threads or the threading issue is handled inside the directory object?

Thanks

Charles Zhang
 
W

Walter Wang [MSFT]

Hi Charles,

The HttpContext.Current is per-request, which means every worker thread has
its own Items collection; therefore different request/session will have
their own HttpContext.Current. If you spawn a new background thread from
the worker thread that is currently handling the request, the background
thread will not have this HttpContext.Current.

This also means a second request issued by the same user/session will also
have an brand new HttpContext.Current. This is different from how session
state works across different requests. From your previous code, it seems
you're only saving the state at the beginning of each request and use it
from the dynamic web page, that's why I suggested to use it; otherwise it
will not work if you need to access previous state in
VirtualPathProvider/VirtualFile.

Following are some reference articles you may find useful on
HttpContext/CallContext:

#Working With HttpContext.Current
http://www.odetocode.com/Articles/112.aspx


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Charles,

Let me know if you have further questions. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top