Reputation: 453
When i'm launch my web api application from visual studio all seems to work perfect. But when i'm trying to publish it and run it via IIS7 it doesnt work.
First step i create a controller with name Person.
public class PersonController : ApiController
{
// GET: api/Person
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/Person/5
public string Get(int id)
{
return "value";
}
// POST: api/Person
public void Post([FromBody]string value)
{
}
// PUT: api/Person/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE: api/Person/5
public void Delete(int id)
{
}
Then i'm choosing Publish, and selecting IIS,FTP,etc. Then i'm selecting Filesystem and rooting my path:
Here is my files inside folder
Then inside IIS i choose add new web site:
Now when i'm opening and trying to access in my controller i'm getting error below: http://localhost:8080/FirstSite/api/person
Is there something am i doing wrong? Is there something wrong with my files which i export?
Upvotes: 1
Views: 320
Reputation: 38
try adding the below to your hosted web.config
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>
Upvotes: 1
Reputation: 11
If you added a website and left the hostname blank, you should access your API at http://localhost:8080/api/person
Upvotes: 1