473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ASP.Net design flaw!?

Has anyone ever encountered this problem? (I searched on google for
past posts but didn't find anything)

I have a class implementing the IHttpModule Interface. It's mainly
used for seting up layout information & provide some security/logging
functions. Typically it inspects a HttpRequest, set some variables
into session, and returns.

for exactness, the HttpModule is hooked up to these events

PreRequestHandlerExecute
PostRequestHandlerExecute

The strange thing is, depending on the content of the ASPX page that
the Http Request is for, sometimes HttpContext.Session is not
available for the HttpModule.

It turns out that if the targeted aspx page does not have any
code-behinds or scriptlet blocks.. or any code whatsoever. ASP.Net
creates a handler object for that request/aspx page which does not
implement IRequiresSessionState interface, hence no session.

Now that is fine since you would never need to access session info
from an aspx page that contains no code. But in my case.. the
HttpModule DOES..

So, given the problem stated.. I thought the way to solve it would be

override Page class and implement the IRequreSessionState Interface in
a new class.
specify the pageBaseType attribute in the pages directive under
web.config to the new class.

and of course it didn't work!! Can anyone suggest anything else?
(other than adding a code block to every single aspx page) or at least
explain why my work around is futile.

Any input will be greatly appreciated.

Thanks!
Nov 18 '05 #1
6 1321

"Kevin" <do*************@yahoo.com> wrote in message
news:97**************************@posting.google.c om...
Has anyone ever encountered this problem? (I searched on google for
past posts but didn't find anything)

I have a class implementing the IHttpModule Interface. It's mainly
used for seting up layout information & provide some security/logging
functions. Typically it inspects a HttpRequest, set some variables
into session, and returns.

for exactness, the HttpModule is hooked up to these events

PreRequestHandlerExecute
PostRequestHandlerExecute

The strange thing is, depending on the content of the ASPX page that
the Http Request is for, sometimes HttpContext.Session is not
available for the HttpModule.

It turns out that if the targeted aspx page does not have any
code-behinds or scriptlet blocks.. or any code whatsoever. ASP.Net
creates a handler object for that request/aspx page which does not
implement IRequiresSessionState interface, hence no session.

Now that is fine since you would never need to access session info
from an aspx page that contains no code. But in my case.. the
HttpModule DOES..

So, given the problem stated.. I thought the way to solve it would be

override Page class and implement the IRequreSessionState Interface in
a new class.
specify the pageBaseType attribute in the pages directive under
web.config to the new class.

and of course it didn't work!! Can anyone suggest anything else?
(other than adding a code block to every single aspx page) or at least
explain why my work around is futile.

Any input will be greatly appreciated.

Thanks!


Can you check if HttpContext.Session != null ??
then you can skip your code-block if the requested page will not be able
to make use of it anyway.

Hans Kesting
Nov 18 '05 #2
Even though the requested page does not require Session info, in my
case, the HttpModule must record the url of the resource that the user
is accessing, and save that information into the SessionState. The
user's path through the application is then used to make decisions for
subsequent requests.

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message news:<uZ*************@TK2MSFTNGP10.phx.gbl>...
"Kevin" <do*************@yahoo.com> wrote in message
news:97**************************@posting.google.c om...
Has anyone ever encountered this problem? (I searched on google for
past posts but didn't find anything)

I have a class implementing the IHttpModule Interface. It's mainly
used for seting up layout information & provide some security/logging
functions. Typically it inspects a HttpRequest, set some variables
into session, and returns.

for exactness, the HttpModule is hooked up to these events

PreRequestHandlerExecute
PostRequestHandlerExecute

The strange thing is, depending on the content of the ASPX page that
the Http Request is for, sometimes HttpContext.Session is not
available for the HttpModule.

It turns out that if the targeted aspx page does not have any
code-behinds or scriptlet blocks.. or any code whatsoever. ASP.Net
creates a handler object for that request/aspx page which does not
implement IRequiresSessionState interface, hence no session.

Now that is fine since you would never need to access session info
from an aspx page that contains no code. But in my case.. the
HttpModule DOES..

So, given the problem stated.. I thought the way to solve it would be

override Page class and implement the IRequreSessionState Interface in
a new class.
specify the pageBaseType attribute in the pages directive under
web.config to the new class.

and of course it didn't work!! Can anyone suggest anything else?
(other than adding a code block to every single aspx page) or at least
explain why my work around is futile.

Any input will be greatly appreciated.

Thanks!


Can you check if HttpContext.Session != null ??
then you can skip your code-block if the requested page will not be able
to make use of it anyway.

Hans Kesting

Nov 18 '05 #3
"Kevin" <do*************@yahoo.com> wrote in message
news:97**************************@posting.google.c om...
Even though the requested page does not require Session info, in my
case, the HttpModule must record the url of the resource that the user
is accessing, and save that information into the SessionState. The
user's path through the application is then used to make decisions for
subsequent requests.


Kevin,

I question this design. I gather that right now, the user signals a desire
to change state by clicking on links, which direct them to the page which
represents the state change? But why equate the path through the application
with the changes in the users state? What if, at a later date, you decide to
add a pop-up at some point, perhaps without changing the state?

Instead, why not have the link post back to the current page, and have the
page change the state then either use Response.Redirect or Server.Transfer
to go to the desired new page? That way, the page (which has Session
available) would be what changes the state. You wouldn't need an HttpModule
to translate URLs into state.
--
John Saunders
John.Saunders at SurfControl.com
Nov 18 '05 #4
Hi John,

Thanks for your response, but I think we're getting off topic. I was
really hoping someone (Any MSFT employees??) could address the
technical aspect of how ASP.Net handles SessionState in the scenario
provided.

In all fairness, I should give more detail about what the HttpModule
is doing so that the question makes more sense! (Please see earlier
post in this thread for more info..)

We're trying to design our application so that it changes behavior
depending on what the user has seen. So if the user has viewed
certain pages, we will change the application to customize their
experience.

We opt not to use post backs or other server side events because this
is not supposed to be an intrusive function, the user is not actively
providing feedback. Instead, we want to quietly profile the path the
user is taking through our application and make display/marketing
decisions further down the process.

The problem is, some of these files along the way could be just simple
ASPX files with no scriplet blocks or any code whatsoever. In those
cases, SessionState is not created, and the HttpModule cannot
store/access any information from it.

Overriding the Page class and specifying a basePage type in the
web.config did not solve the problem. Leading me to believe ASP.Net
optimizes code-free ASPX pages by piping it straight out without
following the usual rules of ASPX page life cycle. That decision
doesn't really make sense to me.

Can someone provide a work-around without requiring that every single
ASPX be created with a scriptlet block?

"John Saunders" <john.saunders at SurfControl.com> wrote in message news:<eS**************@TK2MSFTNGP10.phx.gbl>...
"Kevin" <do*************@yahoo.com> wrote in message
news:97**************************@posting.google.c om...
Even though the requested page does not require Session info, in my
case, the HttpModule must record the url of the resource that the user
is accessing, and save that information into the SessionState. The
user's path through the application is then used to make decisions for
subsequent requests.


Kevin,

I question this design. I gather that right now, the user signals a desire
to change state by clicking on links, which direct them to the page which
represents the state change? But why equate the path through the application
with the changes in the users state? What if, at a later date, you decide to
add a pop-up at some point, perhaps without changing the state?

Instead, why not have the link post back to the current page, and have the
page change the state then either use Response.Redirect or Server.Transfer
to go to the desired new page? That way, the page (which has Session
available) would be what changes the state. You wouldn't need an HttpModule
to translate URLs into state.

Nov 18 '05 #5
"Kevin" <do*************@yahoo.com> wrote in message
news:97**************************@posting.google.c om...
Hi John,

Thanks for your response, but I think we're getting off topic. I was
really hoping someone (Any MSFT employees??) could address the
technical aspect of how ASP.Net handles SessionState in the scenario
provided.

In all fairness, I should give more detail about what the HttpModule
is doing so that the question makes more sense! (Please see earlier
post in this thread for more info..)

We're trying to design our application so that it changes behavior
depending on what the user has seen. So if the user has viewed
certain pages, we will change the application to customize their
experience.

We opt not to use post backs or other server side events because this
is not supposed to be an intrusive function, the user is not actively
providing feedback. Instead, we want to quietly profile the path the
user is taking through our application and make display/marketing
decisions further down the process.

Actually, my recommendation stands.

In order not to stray too far off-topic, I'll just ask you what you want
your application to do if the user creates a new browser window with, e.g.,
the IE File->New->Window command? I believe that the new window would share
session state with the original window, yet the user could use the new
window to browse a totally different path than the original. In general, the
sequence of requested URLs may not always give you what you want.

If the session cookie is available to your HttpModule, you might try using
it as the key into a hash table you store in Application state.
--
John Saunders
John.Saunders at SurfControl.com
Nov 18 '05 #6
Hi John,

In our case, we want to know whether or not a user has seen a
particular banner/advertisement/content. If they have seen it at ANY
POINT during their visit to the site, we will show them a narrowed set
of offers/promotions when they request other pages from the site. The
order of visit is not important, just as long as they are logged.

So regardless of whether the user opens a new window or not.. As soon
as they come to any dynamic pages containing product offers, we will
make use of their session information to determine what offer to best
display to the user.

For example, if the user has seen a page containing information about
Sneakers, we want to show them promotions regarding sneakers in
prominent spots on other pages of the site.

Finally, yes, the session cookie is available to the HttpModule, and I
have considered using it to store variables.. basically re-creating
what SessionStateModule is already doing in AcquireRequestState. It
will work as long as we stay with cookie-based sessions... it just
seems like extra work that shouldn't be necessary in a well designed
app server.

Thanks,
Kevin
"John Saunders" <john.saunders at SurfControl.com> wrote in message news:<#n*************@TK2MSFTNGP11.phx.gbl>...
Actually, my recommendation stands.

In order not to stray too far off-topic, I'll just ask you what you want
your application to do if the user creates a new browser window with, e.g.,
the IE File->New->Window command? I believe that the new window would share
session state with the original window, yet the user could use the new
window to browse a totally different path than the original. In general, the
sequence of requested URLs may not always give you what you want.

If the session cookie is available to your HttpModule, you might try using
it as the key into a hash table you store in Application state.

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Daniel Silva | last post by:
Shriram Krishnamurthi has just announced the following elsewhere; it might be of interest to c.l.s, c.l.f, and c.l.p: http://list.cs.brown.edu/pipermail/plt-scheme/2005-April/008382.html The...
10
by: ma740988 | last post by:
I'm hoping my post here doesn't fall into the 'hard to say' category, nonetheless I've been advised that multiple uses of accessor/mutator (get/set) member functions can be viewed as a 'design...
0
by: Andrew | last post by:
Why is that HttpWebRequest (client request) has certificates as a collection (you can attach multiple certificates to a client request) and HttpRequest has only property for a signle client...
11
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure...
6
by: thomson | last post by:
Hi I do have an Interface, which is implemented in lot of places, My question is i observed that After quite some time if i need to add a new method in the interface , i need to do a lot of...
12
by: Adil Akram | last post by:
I'm using VS 2005, .net 2.0 for a desktop application (Window Form app). I can't set ZOrder of Panel control neither at design time by toolbar/menu command "Bring to Front"/"Sent to Back" nor at...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
12
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a...
7
by: skip | last post by:
This question was posed to me today. Given a C/C++ program we can clearly embed a Python interpreter in it. Is it possible to fire up multiple interpreters in multiple threads? For example: ...
4
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I use unbound DataGridView controls in my form (simply because I have to manually message my data before populating the DataGridView with it). Say I clear all the info from the DataGridView: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.