繁体   English   中英

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

[英]Can't get my Asp.Net Core project to work published to folder on localhost

当我从Visual Studio> IIS Express运行它时,我的Asp.Net Core 2.0 MVC应用程序运行良好,但是当我发布到文件夹(c:\\ inetpub \\ TSGOnline)(TSGOnline是我的解决方案的名称)后,我仅在以下位置看到此错误消息浏览器: 它告诉我将环境更改为Production,它将可以正常工作

但是在Visual Studio中,我确实将ASPNETCORE_ENVIRONMENT设置为Production。 据我所知,环境就是生产环境

我的操作系统是Windows 10,IIS版本是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?}");
                });
            }
        }
    }

我的csproj: 我无法将其粘贴为代码,因此必须使用图片

我花了两天的时间进行谷歌搜索,试图弄清楚这一点,但是作为一个菜鸟,我可能并不总是知道答案何时就在我眼前……请帮助?

对于IIS应用程序。 您需要在IIS应用程序或系统变量中设置该变量。

请查看章节设置环境

https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/environments

视窗

要为当前会话设置ASPNETCORE_ENVIRONMENT ,如果使用dotnet run启动应用程序,则使用以下命令

Command Line:
set ASPNETCORE_ENVIRONMENT=Development

PowerShell:
$Env:ASPNETCORE_ENVIRONMENT = "Development"

这些命令仅对当前窗口有效。 关闭窗口后, ASPNETCORE_ENVIRONMENT设置将恢复为默认设置或计算机值。

为了在Windows上全局设置值,请打开控制面板>系统>高级系统设置,然后添加或编辑ASPNETCORE_ENVIRONMENT值。

每个IIS应用程序池:

如果需要为在隔离的应用程序池(在IIS 10.0+中受支持)中运行的单个应用程序设置环境变量,请参阅IIS参考文档中“环境变量<environmentVariables>主题的AppCmd.exe命令部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM