簡體   English   中英

ASP.NET Web API 在 IIS 中發布時不起作用?

[英]ASP.NET Web API does not work when publish it in IIS?

當我從 Visual Studio 運行或瀏覽它時,我已經構建了一個 ASP.NET Web API,它工作正常,但是當我將它托管在 IIS 中並嘗試瀏覽它時,它不起作用並給我以下錯誤:

HTTP 400 錯誤不是你,是這個鏈接(好像壞了)

在這里我發布我的網絡服務在此處輸入圖片說明

API方法是

 [HttpGet]
    [Route("findall")]
    public HttpResponseMessage findAll()
    {
        try
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StringContent(JsonConvert.SerializeObject(mde.Products.ToList()));
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return response;

        }
        catch
        {
            return new HttpResponseMessage(HttpStatusCode.BadRequest);
        }
    }

我向它發送以下請求:

http://localhost:9810/api/product/findall

我該如何解決這個問題?

根據屏幕截圖,您已將應用程序部署為默認站點上的虛擬應用程序。 並且/myserver被定義為虛擬路徑。 這意味着您的 API 根 URL 將是:

http://localhost:{IIS_PORT}/myserver/{YOUR_APP_ROUTES}

默認網站端口為 80; 如果您帖子中的 URL ( http://localhost:9810/api/product/findall ) 在 IIS-express 上正常工作,請嘗試為您的 IIS 部署調用此 URL:

http://localhost/myserver/api/product/findall

在命令提示符下執行此命令

%windir%\\Microsoft.NET\\Framework\\v4.0.21006\\aspnet_regiis.exe -i

對我來說它解決了這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM