【发布时间】:2019-03-11 01:29:11
【问题描述】:
假设我们采用默认 VS 模板之一生成的默认 asp netcore 2.2 应用程序。
运行dotnet publish --Release 后,我们会得到一个包含应用程序二进制文件的文件夹。
在默认http://localhost:5000 上运行dotnet MyDemo.dll 为应用加注星标。
如何更改默认端口和主机?
我试过设置ASPNETCORE_URLS环境变量没有效果。
一些额外的上下文:我知道对于本地开发,我们可以在 launchSettings.json 中设置不同的配置文件,我们可以使用dotnet run 命令来选择要运行的配置文件。但是,发布后没有 launchSettings.json 并且直接使用 dotnet MyDemo.dll 运行二进制文件似乎不允许任何额外的配置。
请参阅下面的 Startup 类。
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseMvc();
}
}
【问题讨论】:
标签: c# asp.net-core