LoginSignup
1
0

More than 3 years have passed since last update.

.NETCore3.1でDevelopmentモードに変更する

Last updated at Posted at 2020-06-17

めちゃくちゃ単純な話ですが、探すと意外と見つからない。
こいつが設定できないとずっとただの「500 Error」となり、場合によってはデバッグ不能となる。

答えはコレ

Program.cs

public static void Main(string[] args)
{
     Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");  //追記
     CreateHostBuilder(args).Build().Run();
}

Startup.cs

あとはStartup.csのほうでこうなってればOK
※mvcでProjectを立てたら最初からこうなってました。

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment()) //ここがtrueになるので
    {
        app.UseDeveloperExceptionPage(); //これが効く
        app.UseDatabaseErrorPage();  //これも効く
    }
    else
    {
        app.UseExceptionHandler("/Home/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.UseHttpsRedirection();
    app.UseStaticFiles();

    app.UseRouting();

    app.UseAuthentication();
    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
        endpoints.MapRazorPages();
    });
}

おわり

Startup.csの話はあちこちに書いてあるんですけどね。
Program.csのほうがなかなかレアでした。

1
0
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
1
0