pre-process to ASP.NET...

P

Paul Colton

I want to pre-process some of my pages using some custom code, then output
the ASP.NET page so the regular ASP.NET handler takes care of it. I'd like
for page caching, etc. to work as normal.

What's the best approach?

-Paul
 
T

Teemu Keiski

Hi,

I believe an HTTP module or custom code in global.asax would be what you are
looking for. In this article there are listed the HttpApplication events you
can wire handlers on (reusable HTTP module or app-specific code in
global.asax, both can get to the same events)
http://www.eggheadcafe.com/articles/20030211.asp

Here is an article about how to implement HTTP modules.
http://www.devx.com/vb2themax/Article/19901/0/page/1

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist




I want to pre-process some of my pages using some custom code, then output
the ASP.NET page so the regular ASP.NET handler takes care of it. I'd like
for page caching, etc. to work as normal.

What's the best approach?

-Paul
 
P

Paul Colton

I can write the HTTP module, but I can't figure out how to change the
filename, or content length, or content itself of the REQUEST, not of the
response. For example, what if I have a text file that contains macros that
I want to expand BEFORE ASP.NET processes the page?

Paul
 
S

Steven Cheng[MSFT]

Hi Paul,


Thanks for posting in the community!
From your description, you'd like to do some pre-process on a certain
ASP.NET web request?

In the former messages, Teemu Keiski has mentioned the means use the
"HttpModules". I thinkyou can also implement the same operations in the
HttpModules in the Application's Global object (Global.asax/
Global.asax.cs). There're also the same events in the Global object to help
you hook the web request's processing. For example:
protected void Application_BeginRequest(Object sender, EventArgs e)
{...}

protected void Application_EndRequest(Object sender, EventArgs e)
{...}

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{...}

Then, if you want to some operations on the Request's data, you can
retrieve the Request object via
"HttpContext.Current.Request" , it has several members to help do some
modifications on it, such as:
HttpContext.Current.Request.InputStream;
HttpContext.Current.Request.FilePath

For more detailed info on the Global object and Request object, you may
view the following reference in MSDN:
#Global.asax File
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcontheglobalasaxfile.
asp?frame=true

#HttpRequest Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebHttpRequest
ClassTopic.asp?frame=true

In addition, since you mentioned that
" what if I have a text file that contains macros that
I want to expand BEFORE ASP.NET processes the page"

Do you mean that you want to do some modification on the certain ASPX
page's page source before it is compiled and used to process the Request?
If so, the aspx( httpHandler) will be created at runtime by HandlerFactory,
though it is described behind the HttpModules in the ASP.NET's pipline, but
it is likely that it has been compiled and created( the instance) when the
certain hooked events(Request_Begin...) is fired. So I think as for such
situation, maybe you can consider implement a custom httphandler which will
deal with the certain kinds of request, then delegate the other detailed
processing behind that httphandler( it is just like a proxy), how do you
think of this?

Here're some tech references and articles on HttpHandlers:
#HttpHandlers
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhttphandlers.asp?f
rame=true

#Implementing Front Controller in ASP.NET Using HTTPHandler
http://msdn.microsoft.com/library/en-us/dnpatterns/html/ImpFrontControllerIn
ASP.asp?frame=true

And here are some other tech articles I've searched on the web:
#ASP.NET MVC Web-Tier
http://moncs.cs.mcgill.ca/people/hv/teaching/MSBDesign/codagen.pdf

Hope they're helpful.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
P

Paul Colton

Then, if you want to some operations on the Request's data, you can
retrieve the Request object via
"HttpContext.Current.Request" , it has several members to help do some
modifications on it, such as:
HttpContext.Current.Request.InputStream;
HttpContext.Current.Request.FilePath

One problem is that InputStream and FilePath are both read-only properties,
so I can't change their values.
In addition, since you mentioned that
" what if I have a text file that contains macros that
I want to expand BEFORE ASP.NET processes the page"

Do you mean that you want to do some modification on the certain ASPX
page's page source before it is compiled and used to process the Request?
If so, the aspx( httpHandler) will be created at runtime by HandlerFactory,
though it is described behind the HttpModules in the ASP.NET's pipline, but
it is likely that it has been compiled and created( the instance) when the
certain hooked events(Request_Begin...) is fired. So I think as for such
situation, maybe you can consider implement a custom httphandler which will
deal with the certain kinds of request, then delegate the other detailed
processing behind that httphandler( it is just like a proxy), how do you
think of this?

Can you explain this further? So let's say I want to pre-process the ASP.NET
source file before handing it over to asp.net, how would I 'delegate' my
updated file over to asp.net?
 
S

Steven Cheng[MSFT]

Hi Paul,

Thanks for your followup. I've done some further research on this issue and
here is some further infos maybe helpful to you:
1. As for how to modify the request content(stream) before it is processed
by the ASP.NET page handler, I think you can make use of the "Filter" for
the Request object. In ASP.NET both the Request and Response object has a
member named "filter" which is a instance of stream for class derieved from
stream, we can use "Filter" to do some certain modification on the Request
before it being processed or on the Response after it has been processed.
As for your situation, I think the Request filter is what you needed , and
you need to use it in a HttpModule or in the Global
object(global.asax/global.asax.cs) 's certain event such as BeginRequest...
For detailed info and example, you can refer to the following tech
articles:

#HttpRequest.Filter Property
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebhttprequest
classfiltertopic.asp?frame=true

#Filtering HTTP Requests with .NET
http://www.ondotnet.com/pub/a/dotnet/2003/10/20/httpfilter.html

2. I also found that in ASP.NET it has provided the URL Rewriting function
which allow use to do some certain redirect actions before the certain
request has been processed. I think this will be helpful if you'd like to
modify the request url path. Here is also a tech article discussing this
topic:

#URL Rewriting with ASP.NET
http://www.codeproject.com/aspnet/URLRewriter.asp

Please check out the above items. If you still feel them not quite
suitable, please feel free to post here. I'll be willing to assit you on
further requests.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
P

Paul Colton

Filters can't alter the size of the request, but it looks like URL rewriting
may be my ticket. Thank you.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top