How do I access 'Request' from a Library?

Discussion in 'ASP .Net' started by =?Utf-8?B?Um9iZXJ0IFcu?=, Apr 28, 2006.

  1. In one of my business objects I wanted to include a method like this:

    public static void PageRedirect(string pageName)
    {
    Response.Redirect(Request.ApplicationPath + "/" + pageName);
    }

    The class is referencing 'System.Web' but yet I'm getting a compile error in
    regard to "Request". How come this method works if sitting in the aspx.cs
    file but not in the cs file in my business object?


    --
    Robert W.
    Vancouver, BC
    www.mwtech.com
     
    =?Utf-8?B?Um9iZXJ0IFcu?=, Apr 28, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?Um9iZXJ0IFcu?=

    Guest

    yep, encountered this problem yesterday. If not executed directly as a
    page, need to use.

    Imports System.Web

    HttpContext.Current.Request.ApplicationPath

    HttpContext.Current.Response.Redirect
     
    , Apr 28, 2006
    #2
    1. Advertising

  3. Excellent. Thanks!!!

    --
    Robert W.
    Vancouver, BC
    www.mwtech.com



    "" wrote:

    > yep, encountered this problem yesterday. If not executed directly as a
    > page, need to use.
    >
    > Imports System.Web
    >
    > HttpContext.Current.Request.ApplicationPath
    >
    > HttpContext.Current.Response.Redirect
    >
    >
     
    =?Utf-8?B?Um9iZXJ0IFcu?=, Apr 28, 2006
    #3
  4. =?Utf-8?B?Um9iZXJ0IFcu?=

    Joerg Jooss Guest

    Thus wrote Robert W.,

    > In one of my business objects I wanted to include a method like this:
    >
    > public static void PageRedirect(string pageName)
    > {
    > Response.Redirect(Request.ApplicationPath + "/" + pageName);
    > }
    > The class is referencing 'System.Web' but yet I'm getting a compile
    > error in regard to "Request". How come this method works if sitting
    > in the aspx.cs file but not in the cs file in my business object?


    The reason you can easily access Request, Response and other intrinsic objects
    is that these are properties of the Page class. If you want to use them in
    a library, you'll have to pass them as method parameters.

    Cheers,
    --
    Joerg Jooss
     
    Joerg Jooss, Apr 28, 2006
    #4
  5. =?Utf-8?B?Um9iZXJ0IFcu?=

    Joerg Jooss Guest

    Thus wrote Joerg,

    > The reason you can easily access Request, Response and other intrinsic
    > objects is that these are properties of the Page class. If you want to
    > use them in a library, you'll have to pass them as method parameters.


    I shouldn't have said "have to" -- of course one can use HttpContext.Current
    to grab the intrinsics, but I usually prefer to use rather explicit interfaces
    and not rely on magic (i.e. runtime or host dependent) static members.

    Cheers,
    --
    Joerg Jooss
     
    Joerg Jooss, Apr 28, 2006
    #5
    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. Steve
    Replies:
    0
    Views:
    5,361
    Steve
    Jul 1, 2003
  2. Daniel Bass
    Replies:
    2
    Views:
    3,735
    dave wanta
    Jul 4, 2003
  3. Christian H
    Replies:
    1
    Views:
    894
    Natty Gur
    Jul 29, 2003
  4. Brian Birtle
    Replies:
    2
    Views:
    2,101
    John Saunders
    Oct 16, 2003
  5. George
    Replies:
    5
    Views:
    6,647
    George
    Apr 2, 2004
Loading...

Share This Page