Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do I access 'Request' from a Library?

Reply
Thread Tools

How do I access 'Request' from a Library?

 
 
=?Utf-8?B?Um9iZXJ0IFcu?=
Guest
Posts: n/a
 
      04-27-2006
In one of my business objects I wanted to include a method like this:

public static void PageRedirect(string pageName)
{
Response.Redirect(Request.ApplicationPath + "/" + pageName);
}

The class is referencing 'System.Web' but yet I'm getting a compile error in
regard to "Request". How come this method works if sitting in the aspx.cs
file but not in the cs file in my business object?


--
Robert W.
Vancouver, BC
www.mwtech.com

 
Reply With Quote
 
 
 
 
tedqn@yahoo.com
Guest
Posts: n/a
 
      04-27-2006
yep, encountered this problem yesterday. If not executed directly as a
page, need to use.

Imports System.Web

HttpContext.Current.Request.ApplicationPath

HttpContext.Current.Response.Redirect

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Um9iZXJ0IFcu?=
Guest
Posts: n/a
 
      04-28-2006
Excellent. Thanks!!!

--
Robert W.
Vancouver, BC
www.mwtech.com



"(E-Mail Removed)" wrote:

> yep, encountered this problem yesterday. If not executed directly as a
> page, need to use.
>
> Imports System.Web
>
> HttpContext.Current.Request.ApplicationPath
>
> HttpContext.Current.Response.Redirect
>
>

 
Reply With Quote
 
Joerg Jooss
Guest
Posts: n/a
 
      04-28-2006
Thus wrote Robert W.,

> In one of my business objects I wanted to include a method like this:
>
> public static void PageRedirect(string pageName)
> {
> Response.Redirect(Request.ApplicationPath + "/" + pageName);
> }
> The class is referencing 'System.Web' but yet I'm getting a compile
> error in regard to "Request". How come this method works if sitting
> in the aspx.cs file but not in the cs file in my business object?


The reason you can easily access Request, Response and other intrinsic objects
is that these are properties of the Page class. If you want to use them in
a library, you'll have to pass them as method parameters.

Cheers,
--
Joerg Jooss
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
Joerg Jooss
Guest
Posts: n/a
 
      04-28-2006
Thus wrote Joerg,

> The reason you can easily access Request, Response and other intrinsic
> objects is that these are properties of the Page class. If you want to
> use them in a library, you'll have to pass them as method parameters.


I shouldn't have said "have to" -- of course one can use HttpContext.Current
to grab the intrinsics, but I usually prefer to use rather explicit interfaces
and not rely on magic (i.e. runtime or host dependent) static members.

Cheers,
--
Joerg Jooss
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very annoying error: Access to the path is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity Jay ASP .Net 2 08-20-2007 07:38 PM
403 Forbidden: You were denied access because: Access denied by access control list Southern Kiwi NZ Computing 6 03-19-2006 05:19 AM
one computer can access shared files the other can't even access =?Utf-8?B?SiBIYW1lcg==?= Wireless Networking 4 12-07-2004 03:13 AM
Desktop can't access Laptop but Laptop can access desktop =?Utf-8?B?Qmx1Y2FkZHk3MQ==?= Wireless Networking 2 11-23-2004 01:52 AM
How do I let people access the internet via an access point but not allow them access to my network yar Wireless Networking 4 09-21-2004 03:48 AM



Advertisments