473,503 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 17 '05 #1
1 9031
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
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
jo****@aspalliance.com

"jg*****@noreply.screenpages.com" <jg*****@screenpages.com> kirjoitti
viestissä news:ff**************************@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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2127
by: Salek Talangi | last post by:
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. Now I want to access the webforms (eg. give a label...
13
3248
by: Alek Davis | last post by:
Hi, Is it possible to access intrinsic ASP objects, such as Request, from a .NET class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can this library retrieve the request info...
2
5190
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb...
0
2241
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
5
3034
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet...
3
4969
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
0
12051
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
6
4841
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
1699
by: Greg Scharlemann | last post by:
There is probably an easy solution to this that I've overlooked somewhere... I have a main file, call it main.php, and an include file, myInclude.php. I'm accessing main.php via:...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.