Dim
Dim

Reputation: 453

Creating a web Api and trying to run it from iis doesnt work

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:

Path

Here is my files inside folder

Files

Then inside IIS i choose add new web site:

Config

Now when i'm opening and trying to access in my controller i'm getting error below: http://localhost:8080/FirstSite/api/person

ErrorImage

Is there something am i doing wrong? Is there something wrong with my files which i export?

Chack configuration

Upvotes: 1

Views: 320

Answers (3)

Dim
Dim

Reputation: 453

Solved. Just neet to set identity in advanced settings as Local System img

Upvotes: 0

themehio
themehio

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

KDG
KDG

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

Related Questions