Custom HTTPModule - Intercept Session Variable Request

Discussion in 'ASP .Net' started by ADN, May 5, 2008.

  1. ADN

    ADN Guest

    Hi, I am creating a custom HTTPModule to intercept the request of when
    the user is attempting to retrieve a session variable. For instance,
    if I set a session variable in my code like so:

    session["myString"] = "Hello World";

    When the request for that session variable "myString" is attempted to
    be retrieved, I would like to intercept that request like so:

    if (Request is for session variable "myString")
    {
    //send this string instead
    }

    Is it even possible to intercept the request of a session variable in
    a custom HTTPModule?
    ADN, May 5, 2008
    #1
    1. Advertising

  2. ADN

    sloan Guest

    If I were faced with a similar issue, I would code up something along these
    lines:

    http://aspalliance.com/810_Implementing_a_Singleton_Pattern_in_C


    and then not code against the Session object directly, but rather through
    this library.

    Then you could subclass as necessary, or override values as needed.

    ...


    StateManager stateManager =StateManager.Instance;
    stateManager.Add("jk","Joydip",State.Session);
    if(stateManager.Get("jk",State.Session)!=null) //<<<you
    can edit the code here to bring back what you want.










    "ADN" <> wrote in message
    news:...
    > Hi, I am creating a custom HTTPModule to intercept the request of when
    > the user is attempting to retrieve a session variable. For instance,
    > if I set a session variable in my code like so:
    >
    > session["myString"] = "Hello World";
    >
    > When the request for that session variable "myString" is attempted to
    > be retrieved, I would like to intercept that request like so:
    >
    > if (Request is for session variable "myString")
    > {
    > //send this string instead
    > }
    >
    > Is it even possible to intercept the request of a session variable in
    > a custom HTTPModule?
    sloan, May 5, 2008
    #2
    1. Advertising

  3. ADN

    ADN Guest

    To add a bit of complexity to this issue, the reason why I wanted to
    use the HttpModule approach is because I have to handle this for
    only .asp files and not for .NET files. So I was thinking that if I
    can just create a custom HttpModule and then configure IIS to use that
    module for.asp pages, I could intercept the request.

    So basically, session information is stored in .asp pages. I want to
    intercept the request when the .asp page attempts to retrieve the
    session value for that particular variable.

    Would I be able to create a custom session provider and wrap it in my
    HttpModule for .asp pages to use? Is this a good approach? Are there
    any better approaches to this?

    Thanks for all your help!
    ADN, May 5, 2008
    #3
  4. ADN

    bruce barker Guest

    asp session is plugable (its just a shared memory dll). you can only cjange
    asp session behavior by changing your asp pages to use a custom session
    manager.

    -- bruce (sqlwork.com)


    "ADN" wrote:

    > To add a bit of complexity to this issue, the reason why I wanted to
    > use the HttpModule approach is because I have to handle this for
    > only .asp files and not for .NET files. So I was thinking that if I
    > can just create a custom HttpModule and then configure IIS to use that
    > module for.asp pages, I could intercept the request.
    >
    > So basically, session information is stored in .asp pages. I want to
    > intercept the request when the .asp page attempts to retrieve the
    > session value for that particular variable.
    >
    > Would I be able to create a custom session provider and wrap it in my
    > HttpModule for .asp pages to use? Is this a good approach? Are there
    > any better approaches to this?
    >
    > Thanks for all your help!
    >
    bruce barker, May 5, 2008
    #4
  5. ADN

    ADN Guest

    Got ya, alright, thank you very much for your help. doesn't look like
    I'm going to be able to do it without modifying each of my .asp pages.
    ADN, May 5, 2008
    #5
  6. The problem you have here is that classic ASP session is a much different
    animal than ASP.NET managed session state, so just mapping your .asp pages to
    get processed through the ASP.NET runtime isn't going to buy you anything.
    You would actually need to replace the classic ASP.DLL non-managed handler.
    -- Peter
    To be a success, arm yourself with the tools you need and learn how to use
    them.

    Site: http://www.eggheadcafe.com
    http://petesbloggerama.blogspot.com
    http://ittyurl.net


    "ADN" wrote:

    > To add a bit of complexity to this issue, the reason why I wanted to
    > use the HttpModule approach is because I have to handle this for
    > only .asp files and not for .NET files. So I was thinking that if I
    > can just create a custom HttpModule and then configure IIS to use that
    > module for.asp pages, I could intercept the request.
    >
    > So basically, session information is stored in .asp pages. I want to
    > intercept the request when the .asp page attempts to retrieve the
    > session value for that particular variable.
    >
    > Would I be able to create a custom session provider and wrap it in my
    > HttpModule for .asp pages to use? Is this a good approach? Are there
    > any better approaches to this?
    >
    > Thanks for all your help!
    >
    Peter Bromberg [C# MVP], May 5, 2008
    #6
  7. ADN

    Madhur Guest

    You do need to create custom HttpModule for this purpose and you won't be
    able to achieve this using that.

    What you need to create is SessionStateProvider which implements this
    interface.

    Remember that ASP.NET 2.0 has a pluggable architecture, you do not need to
    intercept anything, just plug your components instead of the default ones.

    --
    Madhur

    "ADN" <> wrote in message
    news:...
    > Hi, I am creating a custom HTTPModule to intercept the request of when
    > the user is attempting to retrieve a session variable. For instance,
    > if I set a session variable in my code like so:
    >
    > session["myString"] = "Hello World";
    >
    > When the request for that session variable "myString" is attempted to
    > be retrieved, I would like to intercept that request like so:
    >
    > if (Request is for session variable "myString")
    > {
    > //send this string instead
    > }
    >
    > Is it even possible to intercept the request of a session variable in
    > a custom HTTPModule?
    Madhur, May 5, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    812
    Jiong Feng
    Nov 19, 2003
  2. =?Utf-8?B?UlVTU0VMTCBNQ0dJTk5JUw==?=

    Can you intercept the url request before a 404 error occurs?

    =?Utf-8?B?UlVTU0VMTCBNQ0dJTk5JUw==?=, Jul 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    647
    Scott Allen
    Jul 14, 2004
  3. super todd
    Replies:
    1
    Views:
    606
    Bruce Barker
    May 23, 2005
  4. Luis Esteban Valencia
    Replies:
    0
    Views:
    378
    Luis Esteban Valencia
    Jul 8, 2005
  5. =?Utf-8?B?TWF1cml6aW8gUG9sZXR0bw==?=

    Intercept a request with a protocol different from http

    =?Utf-8?B?TWF1cml6aW8gUG9sZXR0bw==?=, Aug 23, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    380
    Kevin Jones
    Aug 23, 2006
Loading...

Share This Page