title: "Handler for Request not found" error after attempting to implement custom ServiceStackHttpHandlerFactory
body: <p>Edit:</p>
  
  <p>The error appears to be related to using <code>location</code> in web.config.</p>
  
  <p>I was able to get the workaround working in a completely new project, however, once I specified a specific location for the API, I started seeing the error again.</p>
  
  <hr>
  
  <p>I have an existing ASP.NET web app that I'm adding Service Stack to. The app relies heavily on ASP.NET Session. Unfortunately I am unable to access sessions in my Service Stack classes as HttpContext.Current.Session is always null.</p>
  
  <p>So I've implemented a VB.NET version of a workaround from <a href="https://stackoverflow.com/a/9193782/118697">this Stack Overflow answer</a>, however when I navigate to the URL Service Stack is configured on, I receive the following error:</p>
  
  <pre><code>Handler for Request not found: 
  
  Request.ApplicationPath: /
  Request.CurrentExecutionFilePath: /api/
  Request.FilePath: /api/
  Request.HttpMethod: GET
  Request.MapPath('~'): D:\Hg\MyApp.Web\
  Request.Path: /api/
  Request.PathInfo: 
  Request.ResolvedPathInfo: /api
  Request.PhysicalPath: D:\Hg\MyApp.Web\api\
  Request.PhysicalApplicationPath: D:\Hg\MyApp.Web\
  Request.QueryString: 
  Request.RawUrl: /api/
  Request.Url.AbsoluteUri: http://localhost:28858/api/
  Request.Url.AbsolutePath: /api/
  Request.Url.Fragment: 
  Request.Url.Host: localhost
  Request.Url.LocalPath: /api/
  Request.Url.Port: 28858
  Request.Url.Query: 
  Request.Url.Scheme: http
  Request.Url.Segments: System.String[]
  App.IsIntegratedPipeline: True
  App.WebHostPhysicalPath: D:\Hg\MyApp.Web
  App.WebHostRootFileNames: [aspnetemail.xml.lic,componentart.uiframework.lic,debug.aspx,debug.aspx.designer.vb,debug.aspx.vb,default.aspx,default.aspx.designer.vb,default.aspx.vb,favicon.ico,global.asax,global.asax.vb,licenses.licx,login.aspx,login.aspx.designer.vb,login.aspx.vb,logout.aspx,logout.aspx.designer.vb,logout.aspx.vb,packages.config,MyApp.web.vbproj,MyApp.web.vbproj.user,readme.txt,robots.txt,switch.aspx,switch.aspx.designer.vb,switch.aspx.vb,web.config,web.debug.config,web.release.config,_app_offline.htm,api,apps,app_code,app_data,app_start,bin,content,error,frameset,homepages,my project,obj,_clientdata,_system]
  App.DefaultHandler: DefaultHttpHandler
  App.DebugLastHandlerArgs: GET|/api/|D:\Hg\MyApp.Web\api\
  </code></pre>
  
  <p>Everything works fine (except Sessions) when I use the default Service Stack HTTP handler. When I swap in <code>SessionHttpHandlerFactory</code>, I get the above error.</p>
  
  <p>According to the instructions on the workaround, you have to change the type attribute from <code>ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack</code> to <code>SomeNamespace.SessionHttpHandlerFactory</code>:</p>
  
  <p><strong>Web.Config</strong>:</p>
  
  <pre><code>&lt;location path="api"&gt;
          &lt;system.web&gt;
              &lt;authorization&gt;
                  &lt;allow users="*" /&gt;
              &lt;/authorization&gt;
              &lt;httpHandlers&gt;
                  &lt;add path="*" type="MyApp.Web.SessionHttpHandlerFactory" verb="*" /&gt;
                  &lt;!--&lt;add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" /&gt;--&gt;
              &lt;/httpHandlers&gt;
          &lt;/system.web&gt;
  
          &lt;!-- Required for IIS7 --&gt;
          &lt;system.webServer&gt;
              &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
              &lt;validation validateIntegratedModeConfiguration="false" /&gt;
              &lt;handlers&gt;
                  &lt;add path="*" name="ServiceStack.Factory" type="MyApp.Web.SessionHttpHandlerFactory" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" /&gt;
                  &lt;!--&lt;add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" /&gt;--&gt;
              &lt;/handlers&gt;
          &lt;/system.webServer&gt;
      &lt;/location&gt;
  </code></pre>
  
  <hr>
  
  <p>Here are the two classes the workaround uses, converted from C# into VB.NET:</p>
  
  <p><strong>SessionHandlerDecorator.vb:</strong></p>
  
  <pre><code>Public Class SessionHandlerDecorator
      Implements IHttpHandler
      Implements IRequiresSessionState
  
      Private Property Handler() As IHttpHandler
          Get
              Return m_Handler
          End Get
          Set(value As IHttpHandler)
              m_Handler = value
          End Set
      End Property
      Private m_Handler As IHttpHandler
  
      Friend Sub New(handler As IHttpHandler)
          Me.Handler = handler
      End Sub
  
      Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
          Get
              Return Handler.IsReusable
          End Get
      End Property
  
      Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
          Handler.ProcessRequest(context)
      End Sub
  End Class
  </code></pre>
  
  <p><strong>SessionHttpHandlerFactory:</strong></p>
  
  <pre><code>Imports ServiceStack.WebHost.Endpoints
  
  Public Class SessionHttpHandlerFactory
      Implements IHttpHandlerFactory
  
      Private Shared ReadOnly factory As New ServiceStackHttpHandlerFactory()
  
      Public Function GetHandler(context As HttpContext, requestType As String, url As String, pathTranslated As String) As IHttpHandler Implements IHttpHandlerFactory.GetHandler
          Dim handler = factory.GetHandler(context, requestType, url, pathTranslated)
          Return If(handler Is Nothing, Nothing, New SessionHandlerDecorator(handler))
      End Function
  
      Public Sub ReleaseHandler(handler As IHttpHandler) Implements IHttpHandlerFactory.ReleaseHandler
          factory.ReleaseHandler(handler)
      End Sub
  
  End Class
  </code></pre>
  
  <hr>
  
  <p>Here is my Service Stack implementation. Like I said, it works perfectly using the default Service Stack HTTP handler.</p>
  
  <p><strong>AppHost.vb:</strong></p>
  
  <pre><code>Imports ServiceStack.WebHost.Endpoints
  
  &lt;Assembly: WebActivator.PreApplicationStartMethod(GetType(LoginAppHost), "Start")&gt; 
  
  Public Class LoginAppHost
      Inherits AppHostBase
  
      Public Sub New()
          'Tell ServiceStack the name and where to find your web services
          MyBase.New("My Happy Login API", GetType(LoginService).Assembly)
      End Sub
  
      Public Overrides Sub Configure(container As Funq.Container)
          'Set JSON web services to return idiomatic JSON camelCase properties
          ServiceStack.Text.JsConfig.EmitCamelCaseNames = True
  
      End Sub
  
      Public Shared Sub Start()
          Dim app As New LoginAppHost
          app.Init()
      End Sub
  End Class
  </code></pre>
  
  <p><strong>Login.vb:</strong></p>
  
  <pre><code>Imports ServiceStack.ServiceInterface
  Imports ServiceStack.ServiceHost
  
  Public Class LoginService
      Inherits Service
  
      Public Function Any(request As SSOLogin) As Object
  
          Return New SSOLoginResponse With {.Valid = True, .RedirectUri = "http://localhost:28858/Iloveturtles.aspx"}
  
      End Function
  
  End Class
  
  &lt;Route("/login")&gt; _
  Public Class SSOLogin
      Public Property UserName As String
      Public Property Key As String
      Public Property Redirect As String
  End Class
  
  Public Class SSOLoginResponse
      Public Property Valid As Boolean
      Public Property RedirectUri As String
  End Class
  </code></pre>
  
  <hr>
  
  <p>I am at a complete loss on how to proceed. Any thoughts?</p>