469,626 Members | 868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Dynamic web pages using VirtualPathProvider


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
Jun 15 '07 #1
5 2709
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 (wa****@online.microsoft.com, 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.

Jun 15 '07 #2
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
Walter Wang [MSFT] wrote:
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 (wa****@online.microsoft.com, 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.
Jun 15 '07 #3
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
Charles Zhang wrote:
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
Walter Wang [MSFT] wrote:
>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 (wa****@online.microsoft.com, 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.
Jun 15 '07 #4
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 (wa****@online.microsoft.com, 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.

Jun 18 '07 #5
Hi Charles,

Let me know if you have further questions. Thanks.
Regards,
Walter Wang (wa****@online.microsoft.com, 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.

Jun 21 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Sandy Pittendrigh | last post: by
reply views Thread by Kenny | last post: by
reply views Thread by Pavel Kocar | last post: by
10 posts views Thread by jflash | last post: by
5 posts views Thread by pittendrigh | last post: by
1 post views Thread by VV | last post: by
9 posts views Thread by pbd22 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.