.NET Web API開発時にLocalではうまくいくもののAzure App Service公開時にControllerがうまく機能しない事例への対処法

It is a common problem When an MVC application is deployed on IIS, the HTTP url which is calling the REST Service exposed by your web API will change. If your api controller is named MyApiController, so in production evironment, you should add the application name before the calling URL. That means that /api/MyApi will become /MyApp/api/MyApi. MyApp is the prefix of your web site (yourwebsite/MyApp).
(.net - Web API interface works locally but gets 404 after deployed to Azure Website - Stack Overflow)

Server側のlaunchSettings.jsonを編集する必要がある。

  "profiles": {
    "XXXX.Server": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      //"applicationUrl": "https://localhost:5000;http://localhost:5001",(Local時の環境)
      "applicationUrl": "https://XXXX.net/;http://XXXX.net/",(公開時のURL)
      "dotnetRunMessages": true
    },

この記事が気に入ったらサポートをしてみませんか?