Jezz Santos - 93 - May 28, 2014

Default redirect?

What I want to achieve is to redirect a request for my SS service at http://localhost  in thebrowser, to: http://localhost/api/metadata

My project is a standard ASP.NET web service. No MVC nothing like that. I am sure at some point this used to work a long time ago, just cant find out how to fix it.

Can anyone explain what is going on, or rather why this does not work for me?
I have the following in web.config (copied from the HelloWorld app):

  <!-- ServiceStack: Required to host at: /api -->
  <location path=“api”>
    <system.web>
      <httpHandlers>
        <add path="" type=“ServiceStack.HttpHandlerFactory, ServiceStack” verb="" />
      </httpHandlers>
    </system.web>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests=“true” />
      <validation validateIntegratedModeConfiguration=“false” />
      <handlers>
        <add path="" name=“ServiceStack.Factory” type=“ServiceStack.HttpHandlerFactory, ServiceStack” verb="" preCondition=“integratedMode” resourceType=“Unspecified” allowPathInfo=“true” />
      </handlers>
    </system.webServer>
  </location>

  <system.web>
    <compilation debug=“true” targetFramework=“4.5” />
    <httpRuntime targetFramework=“4.5” />
    <httpHandlers>
      <add path=“api*” type=“ServiceStack.HttpHandlerFactory, ServiceStack” verb="" />
    </httpHandlers>
  </system.web>

  <!-- Required for IIS 7.0 -->
  <system.webServer>
    <!-- ServiceStack: Required -->
    <modules runAllManagedModulesForAllRequests=“true” />
    <validation validateIntegratedModeConfiguration=“false” />
    <handlers>
      <!-- ServiceStack: Only required for IIS 7.0 -->
      <!–<add name=“ServiceStack.Factory” path=“api” type=“ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack” verb="
" preCondition=“integratedMode” resourceType=“Unspecified” allowPathInfo=“true”/>–>
    </handlers>
  </system.webServer>

That web.config shows that ServiceStack is hosted at /api so ServiceStack is only able to receive requests from /api, i.e. not from root /.

Since it’s just an ASP.NET application you should be able to use a Default.aspx page with a redirect, e.g: http://stackoverflow.com/q/1093081/85785

You can set default requests in ServiceStack with Config.DefaultRedirectPath, which in this case will only let you control where http://localhost/api/ redirects to.

Jezz Santos:

Thanks, that explains it. Is there any way i can get SS to control root AND have my services at /api, and then use SS to get the result i want? I just want to weigh my option here and avoid mixing in asp net noise? Might not be possible. I guess i am trying to learn how SS works better in this area (i.e. DefaultRedirectPath etc.)

Not with MVC which hijacks the request using a HTTP Module. But you can have servicestack hosted at / but mount services at /api by prefixing routes with “/api” which you can do automatically by overriding AppHost.GetRouteAttributes(): See bottom of: https://github.com/ServiceStack/Issues/issues/64

Jezz Santos:

Thanks, that will do it