简体   繁体   English

ASP.NET Web API 在 IIS 中发布时不起作用?

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

I have built an ASP.NET Web API when I run or brows it from Visual Studio its work fine, but when I host it in IIS and try to browse it its not work and give me the following error:当我从 Visual Studio 运行或浏览它时,我已经构建了一个 ASP.NET Web API,它工作正常,但是当我将它托管在 IIS 中并尝试浏览它时,它不起作用并给我以下错误:

HTTP 400 error It's not you, it's this link (it appears to be broken) HTTP 400 错误不是你,是这个链接(好像坏了)

here where i publish my web service在这里我发布我的网络服务在此处输入图片说明

the API method is 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);
        }
    }

I send the following request to it :我向它发送以下请求:

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

how can i fix this issue ?我该如何解决这个问题?

Based on screenshot, you have deployed your application as virtual app on the Default Site.根据屏幕截图,您已将应用程序部署为默认站点上的虚拟应用程序。 And /myserver is defined as virtual path.并且/myserver被定义为虚拟路径。 It means that your API root URL would be:这意味着您的 API 根 URL 将是:

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

For default website port is 80;默认网站端口为 80; If URL from your post ( http://localhost:9810/api/product/findall ) is working on IIS-express correctly, try to invoke this URL for your IIS deployment:如果您帖子中的 URL ( http://localhost:9810/api/product/findall ) 在 IIS-express 上正常工作,请尝试为您的 IIS 部署调用此 URL:

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

Excute this command in command prompt在命令提示符下执行此命令

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

for me its solved the issue对我来说它解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发布到服务器 iis 时,Asp.net web api 返回 404 - Asp.net web api return 404 when publish to server iis 是否可以在Visual Studio 2015的其他端口中发布asp.net Web API? IIS不是IIS Express - Is it possible to publish asp.net web api in a different port in Visual Studio 2015 ? IIS not IIS Express 在IIS上安装ASP.NET Web API - Installing an ASP.NET web API on IIS 使用AngularJS将ASP.NET CORE Web应用程序发布到IIS - Publish ASP.NET CORE web app with AngularJS to IIS 我的 ASP.NET Web 应用程序在 IIS express 上正常运行,但在我发布它时却没有 - My ASP.NET Web application runs normally on IIS express but not when I publish it ASP.NET 核心 api 项目 3.1 发布在 IIS - ASP.NET Core api project 3.1 publish on IIS ASP.NET Core Web API - 当类的成员是接口时,参数绑定不起作用 - ASP.NET Core Web API - Parameter binding does not work when member of a class is an Interface ASP.Net Core Web API 适用于 IIS Express,但在部署到 IIS 时不起作用 - ASP.Net Core Web API works on IIS Express, but not working when deployed to IIS 使用 AWS 中的 SQL Server 数据库发布 ASP.NET WEB API 2 - Publish ASP.NET WEB API 2 with SQL Server database in AWS 无法发布 ASP.NET Web API 到 Z3A580F142203677F1FZ3 应用服务 - Cannot publish ASP.NET Web API to Azure App Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM