Accessing page request / server variables in a class file.

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Accessing page request / server variables in a class file.

    Hi,

    Here's a question for you all. Under "classic" ASP any ASP page could
    have any number of #Include files. Using #Include files I could have
    functions which were common to my whole site and these files had
    access to the Request, Session and Server objects from the page they
    were included on.

    How can this be done under .NET? My understanding is that these
    functions that were once in #Include files should really be part of
    some compiled class which is instantiated on the code-behind page. So
    then my question really is, how can the compiled class reference the
    Request and Server objects of the page that instantiated the class?

    Here's some pseudo code for illustrative purposes....

    File = default.aspx.cs

    public class _default : System.Web.UI.Page
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    try
    {
    // Instantiate my class ...
    classes.c_env C = new classes.c_env();
    Response.Write(C.pageName);
    } catch (Exception e) {
    Response.Write(e.Message);
    }
    }



    File = /Classes/c_env.cs

    public class c_env
    {
    private string pagename;

    // Constructor
    public c_env()
    {
    this.pagename = "";
    }

    // Properties
    public string pageName
    {
    get
    {
    return Request.ServerVariables["SCRIPT_NAME"].ToString();
    }
    }
    }

    How can this separate class access
    Request.ServerVariables["SCRIPT_NAME"].ToString(); from the
    instantiating aspx page?

    Thanks

    John
    jgamble@noreply.screenpages.com Guest

  2. Similar Questions and Discussions

    1. How to Send Request to IIS Server after the Page Displayed
      Hi All, Is that possible that I can send request to IIS Server after a .ASP page is displayed? My Requirement is: Clinet will Fill the...
    2. Accessing an .aspx page from server in a DMZ
      We are currently hosting our own web site; the web site of course resides outside the DMZ. For security reasons, the network crew will not allow us...
    3. Accessing Values of local variables in previous page when using custom error page
      Hello, I have created a nice funky 500 - 100 error page which gives a nicer error; happily loops through and supplies querysting information, all...
    4. Accessing VJ++ COM DLL From ASP Page gives no class def found
      Hi Friends, I had written a VJ++ COM DLL which uses some jar files.I tried to access the DLL from a VB Standard Exe and it worked fine.But,when i...
    5. Accessing variables of another class
      Hello, I have following (probably very basic) problem: I made a html-frameset in VS.net, where the frames itself are aspx-pages with webforms....
  3. #2

    Default Re: Accessing page request / server variables in a class file.

    Import System.Web namespace into the class. Then you can access Context by
    using:

    HttpContext.Current.Response.Write("Something");
    HttpContext.Current.Session["key"]="Value";

    and so on.

    --
    Teemu Keiski
    MCP,Designer/Developer
    Mansoft tietotekniikka Oy
    [url]http://www.mansoft.fi[/url]

    ASP.NET Forums Moderator, [url]www.asp.net[/url]
    AspAlliance Columnist, [url]www.aspalliance.com[/url]

    Email:
    [email]joteke@aspalliance.com[/email]

    "jgamble@noreply.screenpages.com" <jgamble@screenpages.com> kirjoitti
    viestissä news:ffac87bd.0307090310.5173c59b@posting.google.c om...
    > Hi,
    >
    > Here's a question for you all. Under "classic" ASP any ASP page could
    > have any number of #Include files. Using #Include files I could have
    > functions which were common to my whole site and these files had
    > access to the Request, Session and Server objects from the page they
    > were included on.
    >
    > How can this be done under .NET? My understanding is that these
    > functions that were once in #Include files should really be part of
    > some compiled class which is instantiated on the code-behind page. So
    > then my question really is, how can the compiled class reference the
    > Request and Server objects of the page that instantiated the class?
    >
    > Here's some pseudo code for illustrative purposes....
    >
    > File = default.aspx.cs
    >
    > public class _default : System.Web.UI.Page
    > {
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > try
    > {
    > // Instantiate my class ...
    > classes.c_env C = new classes.c_env();
    > Response.Write(C.pageName);
    > } catch (Exception e) {
    > Response.Write(e.Message);
    > }
    > }
    >
    >
    >
    > File = /Classes/c_env.cs
    >
    > public class c_env
    > {
    > private string pagename;
    >
    > // Constructor
    > public c_env()
    > {
    > this.pagename = "";
    > }
    >
    > // Properties
    > public string pageName
    > {
    > get
    > {
    > return Request.ServerVariables["SCRIPT_NAME"].ToString();
    > }
    > }
    > }
    >
    > How can this separate class access
    > Request.ServerVariables["SCRIPT_NAME"].ToString(); from the
    > instantiating aspx page?
    >
    > Thanks
    >
    > John

    Teemu Keiski Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139