简体   繁体   English

无法将我的Asp.Net Core项目发布到本地主机上的文件夹中

[英]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.

相关问题 AddSingleton 在我的 ASP.NET 核心项目中不起作用 - AddSingleton doesn't work in my ASP.NET Core project 无法使套接字在ASP.NET Core中工作 - Can't get sockets to work in ASP.NET Core ASP.NET Core 2.2 MVC MapRoute 项目到 ASP.NET 3.0 端点 MapAreaControllerRoute “无法找到此本地主机页面” - ASP.NET Core 2.2 MVC MapRoute project to ASP.NET 3.0 endpoints MapAreaControllerRoute "This localhost page can't be found" 无法让Jquery datepicker在我的asp.net mvc项目中工作 - Can't get Jquery datepicker to work in my asp.net mvc project asp.net core razor pages project in visual code localhost:5001 return 这个站点无法访问 - asp.net core razor pages project in visual code localhost:5001 return This site can’t be reached ASP.NET Core MVC:找不到这个本地主机页面 - ASP.NET Core MVC : this localhost page can’t be found ASP.NET 核心“找不到这个本地主机页面” - ASP.NET Core “This localhost page can’t be found” 我的项目登录在 asp.net 内核中不起作用 - my project login doesnt work in asp.net core 我发布了我的 ASP.NET Core 6 项目,它发布成功,但是当我 run.exe 文件说 ConnectionString 不能是 null - I published my ASP.NET Core 6 project it published successfully, but when I run .exe file that say ConnectionString cannot be null 无法让我的 C# / ASP.NET Core 6 MVC 应用程序通过 docker 容器在 ZF9D5C19A7F42220333 上工作 - Can't get my C# / ASP.NET Core 6 MVC app to work via a docker container over ssl
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM