Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting ASP.NET 5 WebAPI in IIS using a virtual directory/application

I am trying to host a new ASP.NET 5 WebAPI project in IIS, and I am using the ASP.NET 5 RC 1 runtime. The project that I am using is the standard generated template for a new ASP.NET 5 WebAPI project. (No code changes.)

I have successfully published the project using the command line, and I can get the application to work in a new web site using a specific port, such as localhost:12345. For example, accessing localhost:12345/api/values returns the values.json data from the project template.

However, when I try to use an IIS Application folder for the project, I am getting a 404 error. In other words, localhost:12345/WebApi1/api/values returns a 404 error. But I can see Kestrel running on a random port in the Event Viewer, and if I access the data on that port, I do get values.json back, so I know Kestrel is running.

Is there something special that needs to be done to get an ASP.NET 5 WebAPI project working in an IIS Application folder under a web site?

Side note: if I use --server.urls to set a port for Kestrel, it's running both on the requested port and the random port logged in the Event Viewer. (So it's actually available from Kestrel from 2 URLs, not the single one configured by --server.urls.)

like image 911
Jeff Avatar asked Oct 18 '22 21:10

Jeff


1 Answers

Kiran Challa's link above indeed does fix the problem. Put this in your Configure method in Startup.cs

app.Map("/IISApplicationFolderName", (myAppPath) => this.ConfigureApp(myAppPath, env, loggerFactory));

where IISApplicationFolderName is the name of the IIS application folder that you want to host under. The rest of the configuration code moves to the new method ConfigureApp, since you're delegating your configuration to that method.

This also looks to be a temporary patch until ASP.NET 5 RC2 is released.

like image 126
Jeff Avatar answered Oct 31 '22 15:10

Jeff