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

  • Thread starter Johan Riis Johansen
  • Start date
J

Johan Riis Johansen

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
 
S

Sachin Goregaoker

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
|
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top