首页 文章

无法让我的Asp.Net Core项目在localhost上发布到文件夹

提问于
浏览
0

当我从Visual Studio> IIS Express运行它时,我的Asp.Net Core 2.0 MVC应用程序正常工作,但在我发布到文件夹(c:\ inetpub \ TSGOnline)(TSGOnline是我的解决方案的名称)后,我只看到此错误消息浏览器:It tells me that changing environment to Production, it will work

但在Visual Studio中,我确实将ASPNETCORE_ENVIRONMENT设置为Production . As far as I can tell, the environment is 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:I wasn't able to paste it as code, so had to use image

我花了两天谷歌搜索,试图弄清楚这一个,但作为一个总的菜鸟,我可能不会总是知道答案是什么时候在我面前...请帮助?

1 回答

  • 0

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

    请查看章节设置环境

    https://docs.microsoft.com/en-us/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 命令部分 .

相关问题