[英]Can't get my Asp.Net Core project to work published to folder on localhost
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 当我从Visual Studio> IIS Express运行它时,我的Asp.Net Core 2.0 MVC应用程序运行良好,但是当我发布到文件夹(c:\\ inetpub \\ TSGOnline)(TSGOnline是我的解决方案的名称)后,我仅在以下位置看到此错误消息浏览器: 它告诉我将环境更改为Production,它将可以正常工作
But in Visual Studio, I have indeed set the ASPNETCORE_ENVIRONMENT to Production. 但是在Visual Studio中,我确实将ASPNETCORE_ENVIRONMENT设置为Production。 As far as I can tell, the environment is Production
据我所知,环境就是生产环境
My OS is Windows 10, IIS version is 10.0.15063.0. 我的操作系统是Windows 10,IIS版本是10.0.15063.0。
Program.cs: 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: 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 我的csproj: 我无法将其粘贴为代码,因此必须使用图片
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? 我花了两天的时间进行谷歌搜索,试图弄清楚这一点,但是作为一个菜鸟,我可能并不总是知道答案何时就在我眼前……请帮助?
For IIS
application. 对于
IIS
应用程序。 You need to set that variable either in IIS
application or system variables. 您需要在
IIS
应用程序或系统变量中设置该变量。
Please look at chapter setting environments 请查看章节设置环境
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments https://docs.microsoft.com/zh-cn/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 要为当前会话设置
ASPNETCORE_ENVIRONMENT
,如果使用dotnet run启动应用程序,则使用以下命令
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. 关闭窗口后,
ASPNETCORE_ENVIRONMENT
设置将恢复为默认设置或计算机值。
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. 为了在Windows上全局设置值,请打开控制面板>系统>高级系统设置,然后添加或编辑
ASPNETCORE_ENVIRONMENT
值。
Per IIS Application Pool: 每个IIS应用程序池:
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. 如果需要为在隔离的应用程序池(在IIS 10.0+中受支持)中运行的单个应用程序设置环境变量,请参阅IIS参考文档中“环境变量
<environmentVariables>
主题的AppCmd.exe
命令部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.