This message was discovered on ASPFriends.com 'aspnghttphandlers' 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.
| David Brophy |
-- Copied from [aspngfreeforall] to [aspnghttphandlers] by Charles M. Carroll <Click here to reveal e-mail address> --Hi,I want to return an aspx page to the browser in an HttpHandler. I'd like =to beable to change some stuff in my instance on the Page object before it =getsprocessed.=46or example - look at my made up code below, which illustrates what I =want todo...public class UserControlHandler : IHttpHandler{ public void ProcessRequest(HttpContext context) {=09 Page myPage =3D [LoadPageFromFile("mypage.aspx",context)]; myPage.myTitleProperty =3D "Hello, you requested: " + =context.Request.Url; [context.Response =3D myPage.Response.Output]; // or somthing } public bool IsReusable { get { return true; } }}What do you think?- David BrophyDirector, Cambro Limited,(023) 80 679550=Click here to reveal e-mail address
|
|
| |
| |
| Mark Robson |
I don't know what LoadPageFromFile is (I can't find it in the docs), but can't you just add some parameters to the request (perhaps add a few extra headers) and then use Server.Transfer() ?
I would be skeptical about setting the ASP.NET request up directly because I'm not sure what order the events would need to be fired in.
Then it would operate somewhat like Struts in Java, where you have a controller (Servlet or HttpHandler) which sets parameters up then forwards the request (server-side) to the presentation which is handled by the script layer (JSP or ASP.NET)?
Mark
|
|
| |
|
| |
| David Brophy |
On Wed, 23 Jan 2002 18:31:31 -0000, you wrote:
>I don't know what LoadPageFromFile is (I can't find it in the docs),=20
Sorry, I made that up to illustrate what I wanted to do.
[Original message clipped]
Hmmm, not really what I want to do, but I might look into that....
>I would be skeptical about setting the ASP.NET request up directly = because [Original message clipped]
I did a bit more investigation... It seems I can do sort of what I want = with the following:
public class MyFactory : IHttpHandlerFactory { public virtual IHttpHandler GetHandler(HttpContext context, String requestType, String url, String pathTranslated) { myNamespace.myPageClass h =3D (myNamespace.myPageClass) Activator.CreateInstance (Type.GetType("myNamespace.myPageClass")); =09 return (IHttpHandler)h; }
// This is a must override method. public virtual void ReleaseHandler(IHttpHandler handler) { } }
This will display the output of a page class e.g. if I put "Response.Write("Hello World")" in the Page_Load in the codebehind, it = will display it, _but_ it ignores everything in the .aspx page.
Anyone know a way to instantiate an aspx page object?
- David Brophy Director, Cambro Limited, (023) 80 679550=20 Click here to reveal e-mail address
|
|
| |
|
| |
| David Staheli |
System.Web.UI.Page _aspxPage;
// Get reference to page (modify path to path to page as needed) _aspxPage =3D (System.Web.UI.Page) PageParser.GetCompiledPageInstance(context_.Request.Path, context_.Server.MapPath(context_.Request.Path), context_);
// Process requested page (if postback, the page's event handlers will be called) _aspxPage.ProcessRequest(context_);
-----Original Message----- From: David Brophy [mailto:Click here to reveal e-mail address]=20 Sent: Thursday, January 24, 2002 1:33 AM To: aspnghttphandlers Subject: [aspnghttphandlers] RE: Return an aspx page in an HttpHandler?
On Wed, 23 Jan 2002 18:31:31 -0000, you wrote:
>I don't know what LoadPageFromFile is (I can't find it in the docs),=20
Sorry, I made that up to illustrate what I wanted to do.
[Original message clipped]
Hmmm, not really what I want to do, but I might look into that....
>I would be skeptical about setting the ASP.NET request up directly because [Original message clipped]
I did a bit more investigation... It seems I can do sort of what I want with the following:
public class MyFactory : IHttpHandlerFactory { public virtual IHttpHandler GetHandler(HttpContext context, String requestType, String url, String pathTranslated) { myNamespace.myPageClass h =3D (myNamespace.myPageClass) Activator.CreateInstance (Type.GetType("myNamespace.myPageClass")); =09 return (IHttpHandler)h; }
// This is a must override method. public virtual void ReleaseHandler(IHttpHandler handler) { } }
This will display the output of a page class e.g. if I put "Response.Write("Hello World")" in the Page_Load in the codebehind, it will display it, _but_ it ignores everything in the .aspx page.
Anyone know a way to instantiate an aspx page object?
- David Brophy Director, Cambro Limited, (023) 80 679550=20 Click here to reveal e-mail address
| [aspnghttphandlers] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspnghttphandlers.asp =3D JOIN/QUIT | http://www.asplists.com/search =3D SEARCH Archives
|
|
| |
|
| | |
| | |
| |
| David Brophy |
On Sun, 17 Feb 2002 18:25:25 -0500, you wrote:
>I want to create a mapping between folders in the URL and pages. That = is, I [Original message clipped]
It's difficult.=20
I tried to do this, but I think directories are handled a bit differently= by the isapi routines (someone correct me if I'm wrong!).=20
Also, your page will think it's in a /abc/ directory, so all your client = side url's will have to be absolute (a pain for me).
What i've done is a cludge - 'hijack' one of the unused asp.net file = extensions - e.g. .asax, and map abc.asax --> this.aspx?site=3Dabc
This can easily be done with the instructions earlier in this thread.
I guess you're trying to make your site search-engine friendly?
The reason I hijacked one of the asp.net extensions is just so it's = zero-set-up, you can get the same results by adding a custom isapi filter for the = extension of your choice.
- David Brophy Director, Cambro Limited, (023) 80 679550=20 Click here to reveal e-mail address
|
|
| |
|
| |
| Bob Dombroski |
Havent tried it in 1.0, but in beta 2 what you propose wouldnt work. http://mysite.com/abc/ would not get processed by asp.net, but only by iis, even if your default page in the directory was an aspx file. The request must specifically call a asp.net page (.aspx, .ashx, .asmx or any file ext you map to the aspnet_isapi.dll) for the httphandler to be invoked.
--- Scott <Click here to reveal e-mail address> wrote: [Original message clipped]
__________________________________________________ Do You Yahoo!? Yahoo! Sports - Coverage of the 2002 Olympic Games http://sports.yahoo.com
|
|
| |
|
| |
| David Brophy |
On Mon, 18 Feb 2002 05:04:49 -0800 (PST), you wrote:
[Original message clipped]
Yes, that's more or less what I found.=20
- David Brophy Director, Cambro Limited, (023) 80 679550=20 Click here to reveal e-mail address
|
|
| |
|
| | |
| |
| Steven A Smith (VIP) |
What I would really like to do is allow easy, more descriptive shortcuts to IBuySpy tabs via the URL. So for instance instead of going to http://aspsmith.com/DesktopDefault.aspx?tabindex=2&tabid=32 I'd rather have it read http://aspsmith.com/ibs/
If I can't have that, I suppose I'll make an ASPX page to handle it, like this: http://aspsmith.com/Tab.aspx?name=ibs
but the folder implementation would be my preference.
Steve
----- Original Message ----- From: "David Brophy" <Click here to reveal e-mail address> To: "aspnghttphandlers" <Click here to reveal e-mail address> Sent: Monday, February 18, 2002 6:04 AM Subject: [aspnghttphandlers] RE: Return an aspx page in an HttpHandler?
On Sun, 17 Feb 2002 18:25:25 -0500, you wrote:
>I want to create a mapping between folders in the URL and pages. That is, I [Original message clipped]
It's difficult.
I tried to do this, but I think directories are handled a bit differently by the isapi routines (someone correct me if I'm wrong!).
Also, your page will think it's in a /abc/ directory, so all your client side url's will have to be absolute (a pain for me).
What i've done is a cludge - 'hijack' one of the unused asp.net file extensions - e.g. .asax, and map abc.asax --> this.aspx?site=abc
This can easily be done with the instructions earlier in this thread.
I guess you're trying to make your site search-engine friendly?
The reason I hijacked one of the asp.net extensions is just so it's zero-set-up, you can get the same results by adding a custom isapi filter for the extension of your choice.
- David Brophy Director, Cambro Limited, (023) 80 679550 Click here to reveal e-mail address
| [aspnghttphandlers] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspnghttphandlers.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
|
|
| |
|
| |
| Scott |
I did a similar thing.
In my main navigation table I added a column called PageName. Which I used to map a normal ("somepage.aspx") page name to an ugly page name "index.aspx?navid=34....".
Then in the Application_BeginRequest event:
string pagerequest = Request.Path.ToLower(); if(pagerequest.IndexOf("default") == -1) && pagerequest.IndexOf("logoff") == -1 ) //or any admin page { //look up and retreive "real" page with QueryStrings //If any extra QueryStrings existed, add them to the end (for a forum or etc...) string gotopage = NavigationFunctions.GetVanityPage(pagerequest) + "&" + Request.QueryString; if(gotopage.EndsWith("&")) //remove extra & { gotopage = gotopage.Remove(gotopage.Length - 1, 1); } //RewritePath Context.RewritePath("~/" + gotopage); }
Then on with the rest of the portal.
HTH, Scott
-----Original Message----- From: Steven A Smith [mailto:Click here to reveal e-mail address] Sent: Monday, February 18, 2002 3:34 PM To: aspnghttphandlers Subject: [aspnghttphandlers] RE: Return an aspx page in an HttpHandler?
What I would really like to do is allow easy, more descriptive shortcuts to IBuySpy tabs via the URL. So for instance instead of going to http://aspsmith.com/DesktopDefault.aspx?tabindex=2&tabid=32 I'd rather have it read http://aspsmith.com/ibs/
If I can't have that, I suppose I'll make an ASPX page to handle it, like this: http://aspsmith.com/Tab.aspx?name=ibs
but the folder implementation would be my preference.
Steve
----- Original Message ----- From: "David Brophy" <Click here to reveal e-mail address> To: "aspnghttphandlers" <Click here to reveal e-mail address> Sent: Monday, February 18, 2002 6:04 AM Subject: [aspnghttphandlers] RE: Return an aspx page in an HttpHandler?
On Sun, 17 Feb 2002 18:25:25 -0500, you wrote:
>I want to create a mapping between folders in the URL and pages. That is, I [Original message clipped]
It's difficult.
I tried to do this, but I think directories are handled a bit differently by the isapi routines (someone correct me if I'm wrong!).
Also, your page will think it's in a /abc/ directory, so all your client side url's will have to be absolute (a pain for me).
What i've done is a cludge - 'hijack' one of the unused asp.net file extensions - e.g. .asax, and map abc.asax --> this.aspx?site=abc
This can easily be done with the instructions earlier in this thread.
I guess you're trying to make your site search-engine friendly?
The reason I hijacked one of the asp.net extensions is just so it's zero-set-up, you can get the same results by adding a custom isapi filter for the extension of your choice.
- David Brophy Director, Cambro Limited, (023) 80 679550 Click here to reveal e-mail address
| [aspnghttphandlers] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspnghttphandlers.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
| [aspnghttphandlers] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspnghttphandlers.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
|
|
| |
|
| |
| Gary Pupurs |
On Mon, 18 Feb 2002 15:33:48 -0500, Steven A Smith wrote: [Original message clipped]
This is actually quite EASY to do (but not if you haven't= stumbled on the best way to do it, as David reported).
I'm using it in my CMS project to handle two things: - Handle redirects for moved pages through a database, instead of=
registering the URLs in IIS. - Check to see if page is handled by my custom CMS. (If it is, I= use RewritePath, if not, the request passes through and is handled= like any other ASPX page.)
The cool thing is that this works for any .aspx Url on any= 'discount' ISP, without custom IIS settings. However, if you don't want= .aspx at the end of your URLs, want legacy support for htm and asp redirects(in my case), or prefer to use .html instead of .aspx,= you will have to tell IIS to send all Url requests through the aspnet=
executable.)
(Note that code is untested, I've uninstalled B2 on this machine= and not yet installed V1, sorry for any typos. Also note that the web.config is Beta 2, I think the syntax changed slightly for v1.=
And I can't take complete credit for this code, it's based on= ideas from a VS.NET magazine article.).
Put something similar to this in your web.config: =09=09<httpModules> =09=09=09<add type=3D"IBuySpy.HttpModules.CleanUrlIntercept, =09=09=09IBS.HttpModules" name=3D"IBuySpy.HttpModules" /> =09=09</httpModules>
Then put this in IBuySpy.HttpModules.cs and compile it to a dll= in /bin:
using System; using System.Web;
namespace IBuySpy.HttpModules { =09public class CleanUrlIntercept : IHttpModule =09{ =09=09public void Init(HttpApplication application) =09=09{ =09=09=09//assign event handler to examine incoming page requests =09=09=09application.BeginRequest +=3D =09=09=09=09new EventHandler(Application_BeginRequest); =09=09}
=09=09public void Application_BeginRequest(object sender, EventArgs= e) =09=09{ =09=09=09//cast sender into instance of HttpApplication class =09=09=09HttpApplication application =3D (HttpApplication)sender;
=09=09=09//get the virtual path of the current request =09=09=09string path =3D application.Request.Path;
=09=09=09// This is a simplified way of how I'm using this. =09=09 =09=09=09// LookupOidOfUrl, not included in this sample, just =09=09=09// looks up the URL in a database table and retrieves =09=09=09// the OID (GUID) of that URL, if exists. =09=09=09string urlOid=3D LookupOidOfUrl(path);
=09=09=09if (!urlOid.Equals(String.Empty)) =09=09=09{ =09=09=09// Then I know this Url is part of my CMS, and the page below =09=09=09// should handle it. Any other URLs simply pass through =09=09=09// untouched, so my CMS can coexist with other full ASP.NET =09=09=09// pages and applications on the same site. Nifty. Thanks= MS!
=09=09=09// Rewrite the path to redirect processing of this request to =09=09=09// another .aspx page. The browser URL will remain the =09=09=09// 'clean' URL, unlike if we used Request.Redirect. =09=09=09application.Context.RewritePath("/ShowAzaniPageObject.aspx?oid= =3D" + urlOid); =09=09=09} =09=09} =09 =09} }
Hope that gives you some ideas, Steven.
(I suppose it'd be useful for me to post an article on how to do= this somewhere, I really should get an AspAlliance account, I guess!)
-- Gary Pupurs, Click here to reveal e-mail address on 18/02/2002
|
|
| |
|
| |
| Jeff Widmer |
Steve, This solution has nothing to do with httphandlers but... Why can't you have a default.aspx page in the ibs folder (and any other folder that you want the user to browse to with an easy url) redirect to the correct tab in the DesktopDefault.aspx? In other words:
The user would browse to the http://aspsmith.com/ibs/ directory. The directory has a default page of default.aspx The default.aspx page only contains a redirect to http://aspsmith.com/DesktopDefault.aspx?tabindex=2&tabid=32 assuming tabindex=2 and tabid=32 are correct for the ibs directory. Do the same for any other's such as http://aspsmith.com/store, etc.
To even extend this further, the default.aspx page in each directory could read a database table to determine which tabid to send to in the desktopdefault.aspx.
This may have already been presented to you in another thread or on another list, if it was then this suggestion is way OT.
-Jeff
-----Original Message----- From: Steven A Smith [mailto:Click here to reveal e-mail address] Sent: Monday, February 18, 2002 3:34 PM To: aspnghttphandlers Subject: [aspnghttphandlers] RE: Return an aspx page in an HttpHandler?
What I would really like to do is allow easy, more descriptive shortcuts to IBuySpy tabs via the URL. So for instance instead of going to http://aspsmith.com/DesktopDefault.aspx?tabindex=2&tabid=32 I'd rather have it read http://aspsmith.com/ibs/
If I can't have that, I suppose I'll make an ASPX page to handle it, like this: http://aspsmith.com/Tab.aspx?name=ibs
but the folder implementation would be my preference.
Steve
----- Original Message ----- From: "David Brophy" <Click here to reveal e-mail address> To: "aspnghttphandlers" <Click here to reveal e-mail address> Sent: Monday, February 18, 2002 6:04 AM Subject: [aspnghttphandlers] RE: Return an aspx page in an HttpHandler?
On Sun, 17 Feb 2002 18:25:25 -0500, you wrote:
>I want to create a mapping between folders in the URL and pages. That is, I [Original message clipped]
It's difficult.
I tried to do this, but I think directories are handled a bit differently by the isapi routines (someone correct me if I'm wrong!).
Also, your page will think it's in a /abc/ directory, so all your client side url's will have to be absolute (a pain for me).
What i've done is a cludge - 'hijack' one of the unused asp.net file extensions - e.g. .asax, and map abc.asax --> this.aspx?site=abc
This can easily be done with the instructions earlier in this thread.
I guess you're trying to make your site search-engine friendly?
The reason I hijacked one of the asp.net extensions is just so it's zero-set-up, you can get the same results by adding a custom isapi filter for the extension of your choice.
- David Brophy Director, Cambro Limited, (023) 80 679550 Click here to reveal e-mail address
| [aspnghttphandlers] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspnghttphandlers.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
| [aspnghttphandlers] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspnghttphandlers.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
|
|
| |
|
| |
| Steven A Smith (VIP) |
This is actually what I'm doing currently, but it is a hack and I'd like something that can be managed entirely from the IBS Admin tab, and so it should really not involve creating folders and files and such.
I have an almost working solution using an ASPX file that I'll probably post to my enhancements page on my ASPSmith.com site soon (like this week).
Steve
----- Original Message ----- From: "Jeff Widmer" <Click here to reveal e-mail address> To: "aspnghttphandlers" <Click here to reveal e-mail address> Sent: Tuesday, February 19, 2002 12:13 AM Subject: [aspnghttphandlers] RE: Return an aspx page in an HttpHandler?
[Original message clipped]
|
|
| |
|
|
|
|
|