Search:
Namespaces
Discussions
.NET v1.1
Feedback
Running an ASPX page programmatically
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspnghttphandlers' list
.
Eric M.
-- Moved from [aspngarchitecture] to [aspnghttphandlers] by Charles M. Carroll <
Click here to reveal e-mail address
> --
Hi,
I'm having a problem that I'm hoping someone can help me with. Here is the
scenario:
I have build a web module that intercepts any call to an ASPX file. So if
you call x.aspx the module gets the request and rewrites the path to go to
y.aspx with a querystring that says y.aspx?url=x.aspx
This is all well and good and works, however when the page that I've loaded
this way does a postback it posts to y.aspx?url=x.aspx, and not x.aspx.
So, instead of simply rewriting the path I would like to actually be able to
load the page programmatically. That way the postback is not changed and
the process will be transparent to the user. I do need to be able to tell
the page that I route to what the page was that was actually requested so I
can load the correct user control on that page.
Currently I do somehting like this:
public class theHandler :
IHttpModule
{
#region Impliment Required events for Interface
public void Init(System.Web.
HttpApplication
app)
{
app.BeginRequest += new System.
EventHandler
(this.Begin_Request);
app.EndRequest += new System.
EventHandler
(this.End_Request);
}
public void Dispose(){}
#endregion
public void Begin_Request(object sender, System.
EventArgs
e)
{
HttpApplication app = (HttpApplication)sender;
//this is just the temporary way to get the URL request for testing
string url = app.Context.Request.Url.Segments[2].ToString();
app.Context.RewritePath("template.aspx?a=" + url);
}
Instead of doing the rewrite path I'd like to actualyl generate the page
programmatically but I can't figure out how. app.Context.Server.Execute
seems
to cause the viewstate to get corrupted of screwed up.
The reason that I'm doing this is to create a template driven site where
content is the actualy usercontrol. Any help or ideas you may have would be
very appreciated. Thanks!
-Eric
Reply to this message...
David Staheli
This might be a bit of what you need. It is what ASP.NET does
internally to output an .aspx page (it compiles the page on first hit):
IHttpHandler
httpHandler =3D=20
PageParser.GetCompiledPageInstance(context.Request.Path,
context.Request.PhysicalPath, context);
httpHandler.ProcessRequest(context);
-----Original Message-----
From: Eric M. [mailto:
Click here to reveal e-mail address
]=20
Sent: Friday, March 22, 2002 10:31 AM
To: aspnghttphandlers
Subject: [aspnghttphandlers] Running an ASPX page programmatically
-- Moved from [aspngarchitecture] to [aspnghttphandlers] by Charles M.
Carroll <
Click here to reveal e-mail address
> --
Hi,
I'm having a problem that I'm hoping someone can help me with. Here is
the
scenario:
I have build a web module that intercepts any call to an ASPX file. So
if you call x.aspx the module gets the request and rewrites the path to
go to y.aspx with a querystring that says y.aspx?url=3Dx.aspx
This is all well and good and works, however when the page that I've
loaded this way does a postback it posts to y.aspx?url=3Dx.aspx, and not
x.aspx.
So, instead of simply rewriting the path I would like to actually be
able to load the page programmatically. That way the postback is not
changed and the process will be transparent to the user. I do need to
be able to tell the page that I route to what the page was that was
actually requested so I can load the correct user control on that page.
Currently I do somehting like this:
public class theHandler :
IHttpModule
{
#region Impliment Required events for Interface
public void Init(System.Web.
HttpApplication
app)
{
app.BeginRequest +=3D new
System.
EventHandler
(this.Begin_Request);
app.EndRequest +=3D new
System.
EventHandler
(this.End_Request);
}
public void Dispose(){}
#endregion
public void Begin_Request(object sender, System.
EventArgs
e)
{
HttpApplication app =3D (HttpApplication)sender;
//this is just the temporary way to get the URL request
for testing
string url =3D
app.Context.Request.Url.Segments[2].ToString();
app.Context.RewritePath("template.aspx?a=3D" + url);
}
Instead of doing the rewrite path I'd like to actualyl generate the page
programmatically but I can't figure out how. app.Context.Server.Execute
seems to cause the viewstate to get corrupted of screwed up.
The reason that I'm doing this is to create a template driven site where
content is the actualy usercontrol. Any help or ideas you may have
would be very appreciated. Thanks!
-Eric
| [aspnghttphandlers] member
Click here to reveal e-mail address
=3D YOUR ID=20
|
http://www.asplists.com/asplists/aspnghttphandlers.asp
=3D JOIN/QUIT=20
|
http://www.asplists.com/search
=3D SEARCH Archives
Reply to this message...
Eric M.
Thanks for the reply. I figured there was more to it. The thing is,
now I can process a page, but the module continues on to process the
origional page request. I'd like it to process the page, output the page,
and not continue on to try and output the origional request. Any ideas?
Thanks
Eric
[Original message clipped]
Reply to this message...
David Staheli
Something like this should work:
context.Response.ClearContent(); // Clear any previous output
// Output the page here
context.Response.Flush();
context.Response.End(); // Prevent any additional output
-----Original Message-----
From: Eric M. [mailto:
Click here to reveal e-mail address
]=20
Sent: Friday, March 22, 2002 2:13 PM
To: aspnghttphandlers
Subject: [aspnghttphandlers] RE: Running an ASPX page programmatically
Thanks for the reply. I figured there was more to it. The thing is,=20
now I can process a page, but the module continues on to process the=20
origional page request. I'd like it to process the page, output the
page,=20
and not continue on to try and output the origional request. Any ideas?
Thanks
Eric
[Original message clipped]
| [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
Reply to this message...
Eric M.
David,
I just want to thank you for all of your help. A little more tinkering and
I got it to work. Basically the code does something like this:
HttpApplication
app = (HttpApplication)sender;
IHttpHandler
appHandler = app.Context.Handler;
appHandler =
PageParser
.GetCompiledPageInstance(path, physicalpath,
app.context);
appHandler.ProcessRequest(app.Context);
app.CompleteRequest();
Do you think I'm going to have any problems with output caching and stuff
because of this? I'm doing all of this in the web module BeginRequest
event. Can you think of a more appropriate event where I can do this?
Thanks again for all of your help. I really appreciate it.
-Eric
[Original message clipped]
Reply to this message...
David Staheli
BeginRequest is probably a fine place to do this. I've done some
testing, and ProcessRequest() works fine with output caching. However,
I think I was using an event other than BeginRequest. Just for kicks,
you might want to make sure output caching is working at the
BeginRequest stage. There shouldn't be any problem at all. I tested
this by displaying the date/time on an ASPX page and verifying that,
with output caching, the displayed date/time only changes when the cache
expires.
Side note: during my testing, I was surprised to find that when an ASPX
page does a Server.Transfer(), output caching doesn't kick in for the
page being transferred to.
Good luck!
David
-----Original Message-----
From: Eric M. [mailto:
Click here to reveal e-mail address
]=20
Sent: Friday, March 22, 2002 4:39 PM
To: aspnghttphandlers
Subject: [aspnghttphandlers] RE: Running an ASPX page programmatically
David,
I just want to thank you for all of your help. A little more
tinkering and I got it to work. Basically the code does something like
this:
HttpApplication
app =3D (HttpApplication)sender;
IHttpHandler
appHandler =3D app.Context.Handler;
appHandler =3D
PageParser
.GetCompiledPageInstance(path, physicalpath,
app.context);
appHandler.ProcessRequest(app.Context);
app.CompleteRequest();
Do you think I'm going to have any problems with output caching and
stuff because of this? I'm doing all of this in the web module
BeginRequest event. Can you think of a more appropriate event where I
can do this?
Thanks again for all of your help. I really appreciate it.
-Eric
[Original message clipped]
| [aspnghttphandlers] member
Click here to reveal e-mail address
=3D YOUR ID=20
|
http://www.asplists.com/asplists/aspnghttphandlers.asp
=3D JOIN/QUIT=20
|
http://www.asplists.com/search
=3D SEARCH Archives
Reply to this message...
Eric M.
Sounds great. I'll definitely do some more testing, and thank you
so much for your help. That is insteresting with the Server.Transfer,
I wonder what might be happening. Thanks again!
-Eric
[Original message clipped]
Reply to this message...
System.EventArgs
System.EventHandler
System.Web.HttpApplication
System.Web.IHttpHandler
System.Web.IHttpModule
System.Web.UI.PageParser
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