Reputation: 1602
My Asp.Net Core 2.0 MVC app works fine when I run it from Visual Studio > IIS Express, but after I publish to folder (c:\inetpub\TSGOnline) (TSGOnline is my solution's name), I just see this error message in the browser: It tells me that changing environment to Production, it will work
But in Visual Studio, I have indeed set the ASPNETCORE_ENVIRONMENT to Production. As far as I can tell, the environment is Production
My OS is Windows 10, IIS version is 10.0.15063.0.
Program.cs:
using System.IO; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; namespace TSGOnline { public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() .Build(); } }
Startup.cs:
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using TSGOnline.Models; using Microsoft.EntityFrameworkCore; namespace TSGOnline { 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.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddMvc(); } // 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(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=TSG}/{action=Index}/{id?}"); }); } } }
My csproj: I wasn't able to paste it as code, so had to use image
I have spent two days googling, trying to figure this one out, but being a total noob, I may not always know when the answers are right in front of me ... Please help?
Upvotes: 1
Views: 2648
Reputation: 3880
For IIS
application. You need to set that variable either in IIS
application or system variables.
Please look at chapter setting environments
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments
Windows
To set the ASPNETCORE_ENVIRONMENT
for the current session, if the app is started using dotnet run, the following commands are used
Command Line:
set ASPNETCORE_ENVIRONMENT=Development
PowerShell:
$Env:ASPNETCORE_ENVIRONMENT = "Development"
These commands take effect only for the current window. When the window is closed, the ASPNETCORE_ENVIRONMENT
setting reverts to the default setting or machine value.
In order to set the value globally on Windows open the Control Panel > System > Advanced system settings and add or edit the ASPNETCORE_ENVIRONMENT
value.
Per IIS Application Pool:
If you need to set environment variables for individual apps running in isolated Application Pools (supported on IIS 10.0+), see the AppCmd.exe
command section of the Environment Variables <environmentVariables>
topic in the IIS reference documentation.
Upvotes: 0