IHttpHandlerFactory interaction with VisualStudio

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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
 
I've just realised the "other thread" wasn't your thread, it was "Subject:
Virtual / Dynamic Folder" jd
 
Back
Top