ASP.NET Core 2.0 在 IIS 上出现错误 502.5

5
我将.NET Core 2.0安装到了我的Windows Server 2008上,我的有两个Web项目。它们在我的电脑上都可以工作。但是当我将其中一个发布到服务器时,一个项目可以正常工作而另一个项目会出现以下错误:
HTTP错误502.5 - 进程失败
应用程序'MACHINE/WEBROOT/APPHOST/KI-TAP.COM'的实际根目录为'C:\HostingSpaces\Reseller1\ki-tap.com\wwwroot\',无法通过命令行'dotnet .\ki-tap.dll'启动进程,错误代码为'0x80004005 : 8000808c。
我已经更新了我的 Windows Server,但它仍然显示相同的错误。
这是我的program.cs文件(我没有在此处添加代码。这是默认值)。
  public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }

这里是我的web.config文件(已发布和默认代码):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\ki-tap.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />


  </system.webServer>
</configuration>

以下是我的startup.cs文件(我添加了会话配置):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace ki_tap
{
    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.AddMvc();
            services.AddSession();

        }

        // 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.UseSession();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

编辑:

在@set的建议下,我在Windows Server 2008的cmd控制台中运行了以下命令:

C:\Program Files (x86)\dotnet\dotnet myProjectPath\project.DLL

结果出现以下错误。我该怎么办?

 package: 'Microsoft.AspNetCore.Antiforgery', version: '2.0.1'
 path: 'lib/netstandard2.0/Microsoft.AspNetCore.Antiforgery.dll'
his assembly was expected to be in the local runtime store as the application
s published using the following target manifest files:
 aspnetcore-store-2.0.3.xml

谢谢@Set。我编辑了问题。你可以在问题的末尾看到错误。 - user1688401
1个回答

23

您可能遇到了与aspnet/IISIntegration存储库中描述的此处相同的问题。解决方案是将以下内容添加到.csproj文件中:

<PropertyGroup>
   <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>

一般来说,这个问题的根源在于您本地计算机上的dotnet版本与服务器上的dotnet版本不同。


谢谢,它起作用了。我遇到这个错误是因为我的开发机更新到了2.x.x版本,而部署服务器仍是2.y.y版本。 - Irfan Ashraf
我在AWS EC2实例中有一个新的Windows服务器。如果我在其中安装所有与.Net Core相关的内容,例如Runtime,它会工作吗? - Harry .Naeem

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接