The folder information does not exist. It is just to check in code that the user is requesting db query, rather than a page.
My httpmodule looks like this: The event Iam handling is PreSendRequestContent
Public
Sub MyPreSendRequest(ByVal sender
As
Object,
ByVal e
As EventArgs)
Dim context
As HttpApplication =
CType(sender, HttpApplication)
Dim myPath
As
String = context.Request.Path
If myPath.Contains("information")
Then
Dim pathSplitter()
As
String = context.Request.Url.Segments
Dim countSegments
As
Integer = pathSplitter.Count()
Dim nameString
As
String = (pathSplitter(countSegments - 1).Replace("%20",
" "))
However, what I want to know is whether this is THE CORRECT EVENT to handle? I tried this in BeginRequest as well but it returns 404 error. To deal with 404, I added an empty folder information to my application. However, my aim is to do
this WITHOUT ADDING FOLDERS OR FILES OR CREATING TRICK FILES. And, that is when I discovered PreSendRequestContent. So my question is, is this approach correct? Should I handle this in PreSendRequestContent, or should I handle in BeginRequest
(and use context.rewritepath to rewrite path to an existing page and then output information)?
PreSendRequestContent occurs just before ASP.NET sends content to the client while BeginRequest occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request. You do can achieve what you want by using PreSendRequestContent event.
Also, you can try the BeginRequest event, for more details on how to do it, you may try the following post which may be helpfult to you.
One thing that might throw you for a loop. IIS 5/6 and IIS 7.x will cause this solution to behave differently. In the former, ASP.NET events will not fire for requests that IIS 5/6 can't match to a file. The workarounds for this problem are the same as
those for setting up ASP.NET routing in IIS 5/6. See this post for more details:
http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
I'm not 100% sure on this, but I think that in IIS 7 (running in Integrated Pipeline mode only, I think), your modules will run for non-existent file/path handlers at or below an application. Alternatively, you may be able to configure CustomErrors in web.config
and add a mapping for 404 (Page Not Found) errors to force it to run a page or HTTP handler. I'm not sure if it would change the URL on you or not, but it would get your code to run.
betamax
Member
37 Points
44 Posts
PreSendRequestContent: check for non existing folders and files in the app
Jan 16, 2009 03:41 PM|LINK
Hi all,
I am trying to develop an application where a user can query the database in the URL of this format:
http://www.mydomain.com/information/username
The folder information does not exist. It is just to check in code that the user is requesting db query, rather than a page.
My httpmodule looks like this: The event Iam handling is PreSendRequestContent
Public Sub MyPreSendRequest(ByVal sender As Object, ByVal e As EventArgs) Dim context As HttpApplication = CType(sender, HttpApplication) Dim myPath As String = context.Request.Path If myPath.Contains("information") Then Dim pathSplitter() As String = context.Request.Url.Segments Dim countSegments As Integer = pathSplitter.Count() Dim nameString As String = (pathSplitter(countSegments - 1).Replace("%20", " "))GetDetails(nameString)
context.Response.Clear()
CreateXML.Save(context.Response.Output)
End IfThe above approach works. So if a user request http://www.mydomain.com/information/betamax, information about betamax is returned as XML.
However, what I want to know is whether this is THE CORRECT EVENT to handle? I tried this in BeginRequest as well but it returns 404 error. To deal with 404, I added an empty folder information to my application. However, my aim is to do this WITHOUT ADDING FOLDERS OR FILES OR CREATING TRICK FILES. And, that is when I discovered PreSendRequestContent. So my question is, is this approach correct? Should I handle this in PreSendRequestContent, or should I handle in BeginRequest (and use context.rewritepath to rewrite path to an existing page and then output information)?
Thanks
Nai-Dong Jin...
All-Star
41630 Points
3558 Posts
Re: PreSendRequestContent: check for non existing folders and files in the app
Jan 21, 2009 02:12 AM|LINK
Hi,
PreSendRequestContent occurs just before ASP.NET sends content to the client while BeginRequest occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request. You do can achieve what you want by using PreSendRequestContent event. Also, you can try the BeginRequest event, for more details on how to do it, you may try the following post which may be helpfult to you.
http://forums.asp.net/t/1259390.aspx
Thanks.
sholodak
Member
34 Points
15 Posts
Re: PreSendRequestContent: check for non existing folders and files in the app
Feb 14, 2010 02:54 AM|LINK
Hello,
One thing that might throw you for a loop. IIS 5/6 and IIS 7.x will cause this solution to behave differently. In the former, ASP.NET events will not fire for requests that IIS 5/6 can't match to a file. The workarounds for this problem are the same as those for setting up ASP.NET routing in IIS 5/6. See this post for more details: http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
I'm not 100% sure on this, but I think that in IIS 7 (running in Integrated Pipeline mode only, I think), your modules will run for non-existent file/path handlers at or below an application. Alternatively, you may be able to configure CustomErrors in web.config and add a mapping for 404 (Page Not Found) errors to force it to run a page or HTTP handler. I'm not sure if it would change the URL on you or not, but it would get your code to run.
Also, it kind of seems like you're re-inventing the ADO.NET Data Services wheel. Check out http://en.wikipedia.org/wiki/ADO.NET_Data_Services .
-Scott
www.sholo.net