Ask a Question related to ASP.NET General, Design and Development.
-
jgamble@noreply.screenpages.com #1
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
-
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... -
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... -
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... -
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... -
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.... -
Teemu Keiski #2
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



Reply With Quote

