【发布时间】:2020-03-21 04:07:30
【问题描述】:
我已经向 IIS 发布了一个应用程序,由于我试图访问它,我遇到了环境变量问题。
我已经按照这些步骤Setting up Env. Variables Manually
如果我将其配置为开发,应用程序工作正常,但如果我将其设置为生产,则屏幕上不断显示以下错误消息:Production Error Screen
应用程序正在使用 IIS 10 的 Windows Server 2019 标准版上部署。 认证方式:匿名认证
这是我的 Program.cs:
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace SistemaGestor.SOO.Mvc
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseIISIntegration()
.UseStartup<Startup>();
}
}
这是我的 Startup.cs,没有 using 指令:
namespace SistemaGestor.SOO.Mvc
{
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.AddTransient<SOOContext>(srv => SOOContextFactory.CreateInstance(Configuration));
//Fernando Milanez 25/09/2019
services.AddTransient<IVesselInterface,VesselRepository>();
services.AddTransient<ICountryFlagInterface, CountryFlagRepository>();
services.AddTransient<IAutenticacao, AutenticacaoRepositorio>();
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.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(options =>
{
options.LoginPath = "/Autenticacao/Login";
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
});
services.AddSession(options =>
{
options.Cookie.IsEssential = true;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddSessionStateTempDataProvider();
}
// 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("/Home/Error");
}
RequestLocalizationOptions localizationOptions = new RequestLocalizationOptions
{
SupportedCultures = new List<CultureInfo> { new CultureInfo("pt-BR") },
SupportedUICultures = new List<CultureInfo> { new CultureInfo("pt-BR") },
DefaultRequestCulture = new RequestCulture("pt-BR")
};
app.UseRequestLocalization(localizationOptions);
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseSession();
app.UseAuthentication(); //Requisito para ativar a autenticao, então é sempre assim adiciono o middlewaree depois defino para usar
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Autenticacao}/{action=Login}/{id?}");
});
}
}
}
【问题讨论】:
-
您能否在不设置任何其他环境变量的情况下让 .NET 核心应用程序正常工作?因为您的应用似乎已经在生产模式下运行了。
-
@JokiesDing 仅在调试模式下。问题是当我在发布模式下发布应用程序时。
-
这很奇怪。您是否尝试分析转储文件以找到真正的异常? WINDBG 和 C:\Program Files\dotnet\shared\Microsoft.NETCore.App\x.x.x\sos.dll 可以帮你实现。
标签: c# asp.net-mvc asp.net-core iis