LoginSignup
5
6

More than 5 years have passed since last update.

ASP.NET Core 2.0 実行時 IP及びポートを指定する

Posted at

概要

VisualStudio for Macで ASP.NET Core 2.0 のWebApiを作成しています。
VisualStudioから実行した場合、及び ターミナルからdotnet run した場合、デフォルトでは
localhost:5000
で起動します。
実行するURLを変える方法を調べました。

結論

以下のようにProgram.csを修正する

Program.cs
using System.IO;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace ksHotelWeb
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args)
        {
            return WebHost
                .CreateDefaultBuilder(args)
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseUrls("http://192.168.xx.xx:8080")
                .UseStartup<Startup>()
                .Build();
        }
    }
}

失敗談

プロジェクトの設定を修正(失敗)

オプション.png
※ 変わりません

Properties/launchSettings.jsonを修正(失敗)

launchSettings.json
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:55556/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Sample": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:5000/"
    }
  }
}

※変わりません

dotnet runにて urlsを指定する記事も見かけますが、変化なし。

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6