Accessing intrisic asp.net objects (ie Application, Session) from an assembly

Discussion in 'ASP .Net' started by Johan Riis Johansen, Aug 21, 2003.

  1. Hi Folks!

    A few tips or pointers on this one would be appriciated.

    Presently I'm working on a webproject, and I've decided to
    create a class that acts as template for all pages on the
    site. What all the pages do is inheirit from
    MyTemplatePage instead of System.Web.UI.Page. That works
    fine and everything. My problem actually stems from the
    fact that the same class has to be used for dictating the
    layout of Classic ASP pages (instead of SSI). I have
    converted the class(es) into a Class Library and then
    registered the resulting assembly in the GAC (Global
    Assembly Cache) on the server.

    This also works fine, EXCEPT I can't access the context of
    the caller (aspx-page). I'm not looking for a solution
    where I can access/manipulate with the session object of
    classic asp-pages, but I would like to be able to handle
    the Application, Session, Querystring object of the
    aspx.page in the assembly.
    Is that at all possible? And how is it done?

    I've tried the abvious, just adding a reference to the
    system.web assembly
    from the project, and then just trying this:

    <Code>
    public class MyTempPage : System.Web.UI.Page
    {
    private Boolean p_ContextGetEnabled;
    public MyTempPage()
    {
    try
    {
    if (Application["objMenu"] == null)
    {
    MyMenuClass objMenu = new MyMenuClass();
    Application.Add("objMenu", objMenu);
    if (((MyMenuClass)Application
    ["objMenu"]).TestFunc() //Returns true when called
    p_ContextGetEnabled = true;
    else
    p_ContextGetEnabled = false;
    }
    }
    catch(Exception excep)
    {
    p_ContextGetEnabled = false;
    }
    }

    public Boolean ContextGetEnabled
    {
    get {return p_ContextGetEnabled;}
    }
    ....
    ....
    .... //And so it continues.
    </Code>

    The ContextGetEnabled function ALWAYS returns false :eek:/
    Any help would be very much appricated.

    Thanks in advance.
    JR Johansen
    Johan Riis Johansen, Aug 21, 2003
    #1
    1. Advertising

  2. Hello,
    Please see if the following KB Article helps:

    810928 HOW TO: Access ASP.NET Intrinsic Objects from .NET Components by Using
    http://support.microsoft.com/?id=810928

    Thanks.

    Sincerely,
    Sachin Goregaoker

    Microsoft Developer Support

    This posting is provided "AS IS" with no warranties,
    and confers no rights.
    |
    | Hi Folks!
    |
    | A few tips or pointers on this one would be appriciated.
    |
    | Presently I'm working on a webproject, and I've decided to
    | create a class that acts as template for all pages on the
    | site. What all the pages do is inheirit from
    | MyTemplatePage instead of System.Web.UI.Page. That works
    | fine and everything. My problem actually stems from the
    | fact that the same class has to be used for dictating the
    | layout of Classic ASP pages (instead of SSI). I have
    | converted the class(es) into a Class Library and then
    | registered the resulting assembly in the GAC (Global
    | Assembly Cache) on the server.
    |
    | This also works fine, EXCEPT I can't access the context of
    | the caller (aspx-page). I'm not looking for a solution
    | where I can access/manipulate with the session object of
    | classic asp-pages, but I would like to be able to handle
    | the Application, Session, Querystring object of the
    | aspx.page in the assembly.
    | Is that at all possible? And how is it done?
    |
    | I've tried the abvious, just adding a reference to the
    | system.web assembly
    | from the project, and then just trying this:
    |
    | <Code>
    | public class MyTempPage : System.Web.UI.Page
    | {
    | private Boolean p_ContextGetEnabled;
    | public MyTempPage()
    | {
    | try
    | {
    | if (Application["objMenu"] == null)
    | {
    | MyMenuClass objMenu = new MyMenuClass();
    | Application.Add("objMenu", objMenu);
    | if (((MyMenuClass)Application
    | ["objMenu"]).TestFunc() //Returns true when called
    | p_ContextGetEnabled = true;
    | else
    | p_ContextGetEnabled = false;
    | }
    | }
    | catch(Exception excep)
    | {
    | p_ContextGetEnabled = false;
    | }
    | }
    |
    | public Boolean ContextGetEnabled
    | {
    | get {return p_ContextGetEnabled;}
    | }
    | ...
    | ...
    | ... //And so it continues.
    | </Code>
    |
    | The ContextGetEnabled function ALWAYS returns false :eek:/
    | Any help would be very much appricated.
    |
    | Thanks in advance.
    | JR Johansen
    |
    |
    Sachin Goregaoker, Aug 25, 2003
    #2
    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. SA
    Replies:
    0
    Views:
    464
  2. Ravi Ambros Wallau
    Replies:
    6
    Views:
    497
    Ravi Ambros Wallau
    Jun 17, 2005
  3. Replies:
    3
    Views:
    1,796
  4. Replies:
    5
    Views:
    605
    Vitaly
    Jan 28, 2007
  5. Dax Westerman
    Replies:
    1
    Views:
    176
    Dax Westerman
    Aug 19, 2003
Loading...

Share This Page