0

I need to have WebAPI project working under different base path than usual. I created simple project under Visual Studio that uses WebAPI and ASP.NET 5.

Under base path set to http://localhost:38170/ my project works fine and I'm able to get values from test controller (http://localhost:38170/api/values). At this stage my IIS Express configuration is:

<site name="WebApi" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
   </application>
   <bindings>
        <binding protocol="http" bindingInformation="*:38170:localhost" />
   </bindings>
</site>

I tried changing App URL under project properties to reflect my need: http://localhost:38170/xxx

Now running project and hitting http://localhost:38170/xxx/api/values results in 404. Trying http://localhost:38170/api/values returns values from controller just as if nothing changed. I noticed that changes in Visual Studio are not reflected in IIS Express configuration (I don't know if they should be...) in any way.

I tried changing path on IISExpress manually like in this thread: Creating virtual directories in IIS express.

<site name="WebApi" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/xxx" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
   </application>
   <bindings>
        <binding protocol="http" bindingInformation="*:38170:localhost" />
   </bindings>
</site>

The results are:

http://localhost:38170/api/values - 500.19 Error (config error) and that is fairly ok - I don't plan this to work

http://localhost:38170/xxx/api/values - 502.3 - Bad Gateway on hitting httpPlatformHandler

I suppose that error is somewhere in httpPlatformHandler configuration but I'm not sure how to do it in conjuction with IIS Express. My web.config is:

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
  </system.webServer>
</configuration>

I tried random changes like changes in path attribute to xxx/* but nothing works.

EDIT: To clarify the question.

How to setup WebAPI on ASP.NET 5 (ASP.NET Core) on IISExpress using httpPlatformHandler and Kestrel to set base path other than root.

Community
  • 1
  • 1
pg0xC
  • 1,226
  • 10
  • 20
  • Just to check - try exiting/closing/restarting IISExpress (from the icon in your toolbar). There are reports of issues with IIS, [like this one I _randomly_ hit](http://stackoverflow.com/q/34028341/304683). Not saying its related (I don't know) so just a sanity check (as to why changes in VS properties don't seem to get set) – EdSF Feb 04 '16 at 16:25
  • @EdSF unfortunately checked that hundred and one times - results as described – pg0xC Feb 04 '16 at 16:35

1 Answers1

1

You corrupt the file as your modification does my honor the IIS Express configuration rules.

I will suggest you use a smart tool such as Jexus Manager to manipulate it, and then you can sync the Visual Studio project with the correct URL.

For example, the 404 is expected, as your application tag has path set to /, so there is no application nor virtual directory to serve xxx.

The 500.19 later is also expected, as while adding a valid virtual directory named xxx, you deleted the root virtual directory. That's totally wrong as a root virtual directory must present.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • so what do you suggest to do? Jexus Manager dies without warning so it's not an option. If root virtual directory must be present so where should I point it? - there is no other application there. Moreover httpPlatformHandler seems to be running and handling requests properly - I checked logs. It just receiving bad requests from kestrel or no request at all (I'm not sure) – pg0xC Feb 05 '16 at 08:26
  • @pg0xC, restore the config file to the 404 case, and then add a new virtual directory xxx. The root virtual directory can point to anywhere (but should contain no web.config to avoid introducing other settings). – Lex Li Feb 05 '16 at 09:22
  • Almost there. Situation changed a bit - I get 404's on http://localhost:38170/xxx/api/values because my routing still wants to serve for url xxx/api/values. Api does not work but that is another porblem. Thanks @Lex Li – pg0xC Feb 05 '16 at 09:59