HttpContext question
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngarchitecture' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Tim Royal
Hi there. I'm creating a common DLL for my web app that handles a particular
type of authentication request. If a user fails to have certain credentials
for a given page, I want to redirect them to the no access page. I recognize
that there are other ways to authenticate users with ASP.Net, but I'm
rolling the ASP.Net stuff for this project into an existing framework that
already has other scripting languages using it, so I need to integrate with
this particular system. (Obviously, any new projects come up, I can use the
better methods already available). Anyway,

in the source for the cs file, I had trouble getting the DLL to compile
because it didn't recognize the Request, Response objects, etc.

So, I added a refernce to the System.web, but that didn't work, so I finally
figured out that in my functio if I used HttpContext.Current.Request,
HttpContext.Current.Response, etc. I could access them.

My question is: Is this a reasonable way to handle this? Not sure what
overhead would be incurred by this, or if there's a more direct way. As an
alternative, I could simply pass the information as parameters from the
calling function in the code behind for the page itself.

Any thoughts appreciated. I'm swimming in the vastness of .NET. I'm trying
to really learn the foundation of the ASP.Net framwork, but at the same time
I have to get work done, too. :)

thanks

tim

Reply to this message...
 
    
Kloberg Mac (LAM) (VIP)
Using "HttpContext.Current" in code that is not derived from control/page is
common practice.
AFAIK, there is no overhead involved, since it is just a reference you're
'grabbing' when the executing code doesn't inherit classes that have this
reference readily available (such as control or page).
We do this all the time, nothing to worry about...

hth
--
Sincerely,
Mac Kloberg
LIEBHERR AMERICA INC.
http://www.liebherr-us.com

[Original message clipped]

Reply to this message...
 
    
Paul D. Murphy
It's probably a good idea to put a property in a base class file that
exposes the context. I paste this code into the base class of most
business objects that run in IIS just to make my life easier.

Paul

using System;

namespace NameSpace
{
    #region    Web Base Code Block
    public    class    WebBase
    {
        public    System.Web.HttpContext    Context
        {
            get{    return    System.Web.HttpContext.Current;
}
        }

        public    System.Web.HttpApplication    Application
        {
            get{    return
System.Web.HttpContext.Current.Application;    }
        }

        public    System.Web.SessionState.HttpSessionState
Session
        {
            get{    return    System.Web.HttpContext.Current;
}
        }

        public    System.Web.HttpRequest    Request
        {
            get{    return
System.Web.HttpContext.Current.Request;    }
        }

        public    System.Web.HttpResponse    Response
        {
            get{    return
System.Web.HttpContext.Current.Response; }
        }
    }
    #endregion
}=20

    Paul D. Murphy
    Click here to reveal e-mail address
    "Teamwork is a lot of people doing what I say."

-----Original Message-----
From: Tim Royal [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, July 11, 2002 3:19 PM
To: aspngarchitecture
Subject: [aspngarchitecture] HttpContext question

Hi there. I'm creating a common DLL for my web app that handles a
particular
type of authentication request. If a user fails to have certain
credentials
for a given page, I want to redirect them to the no access page. I
recognize
that there are other ways to authenticate users with ASP.Net, but I'm
rolling the ASP.Net stuff for this project into an existing framework
that
already has other scripting languages using it, so I need to integrate
with
this particular system. (Obviously, any new projects come up, I can use
the
better methods already available). Anyway,

in the source for the cs file, I had trouble getting the DLL to compile
because it didn't recognize the Request, Response objects, etc.

So, I added a refernce to the System.web, but that didn't work, so I
finally
figured out that in my functio if I used HttpContext.Current.Request,
HttpContext.Current.Response, etc. I could access them.

My question is: Is this a reasonable way to handle this? Not sure what
overhead would be incurred by this, or if there's a more direct way. As
an
alternative, I could simply pass the information as parameters from the
calling function in the code behind for the page itself.

Any thoughts appreciated. I'm swimming in the vastness of .NET. I'm
trying
to really learn the foundation of the ASP.Net framwork, but at the same
time
I have to get work done, too. :)

thanks

tim

| [aspngarchitecture] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Mitch Denny
Tim,

There should be no problems doing that. In fact its a very
useful tool for providing access to the ASP.NET cache as
you move futher back through your application layers.

In fact, if you look at the source code for say the Page
class in a tool like Anakrino then you can see that as
part of the processing of a request (ProcessRequest method)
a call to SetIntrinsics is passed along which is just a
reference to the HttpContext anyway.

Its hard to imagine a common scenario where what you
are doing will cause problems.

----------------------------------------
- Mitch Denny
- Technical Specialist
- Click here to reveal e-mail address
- http://www.monash.net
- +61 (414) 610-141
-

-----Original Message-----
From: Tim Royal [mailto:Click here to reveal e-mail address]
Sent: Friday, 12 July 2002 05:19
To: aspngarchitecture
Subject: [aspngarchitecture] HttpContext question

Hi there. I'm creating a common DLL for my web app that handles a
particular type of authentication request. If a user fails to have
certain credentials for a given page, I want to redirect them to the no
access page. I recognize that there are other ways to authenticate users
with ASP.Net, but I'm rolling the ASP.Net stuff for this project into an
existing framework that already has other scripting languages using it,
so I need to integrate with this particular system. (Obviously, any new
projects come up, I can use the better methods already available).
Anyway,

in the source for the cs file, I had trouble getting the DLL to compile
because it didn't recognize the Request, Response objects, etc.

So, I added a refernce to the System.web, but that didn't work, so I
finally figured out that in my functio if I used
HttpContext.Current.Request, HttpContext.Current.Response, etc. I could
access them.

My question is: Is this a reasonable way to handle this? Not sure what
overhead would be incurred by this, or if there's a more direct way. As
an alternative, I could simply pass the information as parameters from
the calling function in the code behind for the page itself.

Any thoughts appreciated. I'm swimming in the vastness of .NET. I'm
trying to really learn the foundation of the ASP.Net framwork, but at
the same time I have to get work done, too. :)

thanks

tim

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
 
System.Web.HttpApplication
System.Web.HttpContext
System.Web.HttpRequest
System.Web.HttpResponse
System.Web.SessionState.HttpSessionState




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com