0
votes

I create a simple Asp.net web api app. It works when running in Visual studio. The url is http://localhost:63082/api/products/1507 when debugging in Visual studio 2013.

I created an IIS website (mySite with port 8081) on a server and publish it using file sharing. However, I always get 404 error when trying the following url on the server.

http://localhost:8081/api/products/1507 (it shows the physical path is c:\inetpub\wwwroot\mySite\api\products\1507 in the error page).

http://localhost:8081/mySite/api/products/1507 (it shows the physical path is c:\inetpub\wwwroot\mySite\mySite\api\products\1507).

Why the url is not working?

The controller method.

    [Route("api/Products/{fileId}")]
    public IEnumerable<Product> GetProductsByFileId(int fileId)
    {
        using (var db = new ProductContext())
        {
            var query = from b in db.Products where b.fileId == fileId select b;
            if (query == null)
            {
                return null;
            }
            return query.ToList();
        }
    }

The following shows all the published files. It seems there is no binary for the app? Is it a problem of Visual studio publishing?

    Directory: \\......\c$\inetpub\wwwroot\mySite


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----          7/6/2015   6:21 PM            bin
-a---          7/6/2015  11:23 AM        101 Global.asax
-a---          7/6/2015   4:50 PM        574 packages.config
-a---          7/6/2015   5:41 PM       4611 Web.config


    Directory: \\......\c$\inetpub\wwwroot\mySite\bin


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          7/6/2015   3:11 PM    5185232 EntityFramework.dll
-a---          7/6/2015   3:11 PM     599760 EntityFramework.SqlServer.dll
-a---          7/6/2015  11:21 AM     502272 Newtonsoft.Json.dll
-a---          7/6/2015  11:21 AM     185032 System.Net.Http.Formatting.dll
-a---          7/6/2015  11:21 AM     471240 System.Web.Http.dll
-a---          7/6/2015  11:21 AM      82120 System.Web.Http.WebHost.dll
-a---          7/6/2015   5:41 PM     109056 webapi.dll
1
You need to check more on IIS side. What is the OS version? Has .NET 4 been registered properly? Lots of things need to be verified.Lex Li
I installed .net 4.5.2 before publishing. The OS version is Windows 2008. How to check if .net 4.5.2 is registered properly?ca9163d9

1 Answers

0
votes

try this :

[Route("api/Products/{fileId}")]
public IHttpActionResult Get(int fileId)
{
    Ok(GetProductsByFileId(fileId));
}

private IEnumerable<Product>  GetProductsByFileId(int fileId)
{
    using (var db = new ProductContext())
    {
        var query = from b in db.Products where b.fileId == fileId select b;
        if (query == null)
        {
            return null;
        }
        return query.ToList();
    }
}