IHttpHandlerFactory interaction with VisualStudio

G

Guest

I am building an IHttpHandlerFactory to process all requests to folders in my
site.

When an attempt to access internal folders is detected the request is
rerouted to an error page.

All other attempts are processed using

return PageParser.GetCompiledPageInstance(url, pathTranslated, context);

This results in a situation created when I start my solution in VisualStudio.

VisualStudio accesses a temporary page
"<domain>/<application>/vs-xxxxx-tmp.htm.

The result is that VisualStudio will not start the web project and says that
the physical location doesn't map to the URL.

What should the IHttpFactory return when it detects a visual studio start
attempt?

Is there a better way to gracefully leave the factory than via PageParser?

Any help would be appreciated.
 
G

Guest

Hi John, another thing i forgot to mention in my last post was to catch
requests for real items... in this case your .proj files


'Ignore real files
If Not IO.File.Exists(c.Server.MapPath(c.Request.Url.AbsolutePath)) Then

'catch your .axd request and ignore processing them

Dim isAXD As Boolean = False
isAXD =
c.Request.Url.AbsolutePath.ToLower.IndexOf("trace.axd") > -1

If Not isAXD Then
' do your processing here
End If




end if
 
G

Guest

Hi John, Sorry for the confusion, the "last post" was the one in the other
thread.

Here is an example of an IHttpModule which should ignore real files e.g. the
..proj files that VS needs when it connects to the web server. It is stripped
out of a project I'm working on at the moment. I've had to take quite a lot
of app specific stuff out and I haven't tested it but... HTH jd

Public Class ExampleModule
Implements Web.IHttpModule


Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

End Sub

Public Sub Init(ByVal app As System.Web.HttpApplication) Implements
System.Web.IHttpModule.Init
AddHandler app.BeginRequest, AddressOf Application_BeginRequest
AddHandler app.EndRequest, AddressOf Application_EndRequest


End Sub

Private Sub Application_BeginRequest(ByVal o As Object, ByVal e As
EventArgs)


Dim app As Web.HttpApplication = CType(o, Web.HttpApplication)
Dim c As Web.HttpContext = app.Context

If Not IO.File.Exists(c.Server.MapPath(c.Request.Url.AbsolutePath))
Then



Dim isAXD As Boolean = False
isAXD = c.Request.Url.AbsolutePath.ToLower.IndexOf("trace.axd")

If Not isAXD Then

c.Items.Add("StartTime", Now.Ticks)


'**************************************************
'
' change this bit to use your own IHttpHandlerFactory
' or Web.UI.PageParser.GetCompiledPageInstance
'
'**************************************************

Dim pathTranslated As String

Dim myFactory As Web.IHttpHandlerFactory
c.Handler = myFactory.GetHandler(c, c.Request.RequestType,
c.Request.Url.ToString, pathTranslated)
c.Handler.ProcessRequest(c)
c.Response.End()
End If
End If




End Sub

Private Sub Application_EndRequest(ByVal o As Object, ByVal e As
EventArgs)
Dim app As Web.HttpApplication = CType(o, Web.HttpApplication)
Dim c As Web.HttpContext = app.Context

Dim t2 As Int64 = Now.Ticks
Dim ts As Int64 = t2 - c.Items.Item("StartTime")

Dim secs As Double = (1 / TimeSpan.FromSeconds(1).Ticks) * ts

'
' do not include the next line if you are streaming binaries!!!
'

'c.Response.Write("<!-- Page Processed in " + secs.ToString + "
seconds. -->")
End Sub

End Class
 
G

Guest

I've just realised the "other thread" wasn't your thread, it was "Subject:
Virtual / Dynamic Folder" jd
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top