为什么我的ASP.NET 5应用程序无法在IIS 7.5上运行?

5
我正在运行带有IIS 7.5的ASP.NET 5(Core)。我已经安装了httpPlatformHandler并将站点的物理路径(在IIS中)设置为来自Visual Studio 2015发布的wwwroot文件夹。但是,我得到的仅是空白的不断加载页面。我很确定我已经正确地连接所有内容。如果我取消注释Configure方法中的app.Run语句并注释掉app.UseIISPlatformHandler、app.UseDefaultFiles、app.UseStaticFiles和app.UseMVC,则可以正常加载。以下是我的代码。我现在不知道该怎么办。有什么建议吗?如果需要其他代码片段,请告诉我。
Startup.cs(Configure方法)
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {

        app.UseIISPlatformHandler();
        app.UseDefaultFiles();
        app.UseStaticFiles();
        app.UseMvc();

        //app.Run(async (context) =>
        //{
        //    var greeting = greeter.GetGreeting();
        //    await context.Response.WriteAsync(greeting);
        //});
    }

web.config

<system.webServer>
<handlers>
  <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" forwardWindowsAuthToken="true" />

新编辑。我已将文件夹结构更新为MVC(使用控制器、视图等),并略微更改了Configure方法。现在它加载一个空白屏幕,控制台记录了404未找到。还有其他建议吗?

附上完整的Startup.cs:

        public IConfiguration Configuration { get; set; }
    public static string ConnectionString { get; set; }

    public Startup()
    {
        var builder = new ConfigurationBuilder()
            .AddJsonFile("appsetting.json")
            .AddEnvironmentVariables();

        Configuration = builder.Build();
        ConnectionString = Configuration.GetSection("connString").Value;
    }

    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
        app.UseIISPlatformHandler();
        //app.UseDefaultFiles();
        app.UseFileServer(true);
        app.UseMvc(routes => 
        {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}");
        });
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);

你有收到任何错误信息吗?你在事件查看器中看到了什么吗? - Babak Naffas
否定。我得到了空白的持续加载页面。没有任何错误。 - Brandon
我下载了v1.2版本,但是我应该去哪里双重检查版本? - Brandon
你是在尝试访问静态文件还是MVC路由?两者都尝试过了吗? - Babak Naffas
我只需要访问我的单个index.html页面,所以我认为我不需要那个app.UseMVC。由于我正在使用的教程中存在这个东西。我对ASP.NET5还很新。不过,这应该不是问题,对吧?在Visual Studio中运行时它可以正常工作。 - Brandon
显示剩余4条评论
2个回答

2
您查看了IIS日志,以确定请求是否已经到达IIS吗?
您还可以尝试在类Startup的Configure()方法中每个中间件模块之间放置一个简单的中间件模块。 您的中间件可以向Windows事件日志写入消息,说明它在Http管道中的位置和响应正文的内容。 就像在调试Javascript时放置警报一样。 这将至少让您知道它卡在哪里或清除响应正文。
我在Github上发布了一个非常易于理解的演示,演示如何通过三个简单步骤创建中间件。 单击此处进入该演示。
更新: 尝试将您的Configure()方法更改为下面的代码(如果我的路由不适用于您的设置,请输入自己的路由)。
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();

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

我刚刚检查了日志,发现有很多“HTTP/1.1 GET /MyApp - 1 Connection_Abandoned_By_ReqQueue No Managed Pool.”的错误信息。但是,我不知道这是什么意思。 - Brandon
这是一个不同的机器吗?当您在Visual Studio中运行时,它能够成功显示页面的那台机器? - Clint B
不是机器翻译。我现在正在使用VS进行调试。这很奇怪。我刚刚对该错误代码进行了一些研究,显然它是某种工作程序,在调用我的启动时崩溃了。我将在上面添加我的startup.cs代码的其余部分。 - Brandon
我更新了我的答案,提供一些尝试的东西。你正在运行 ASP.NET 5 RC1 吗? - Clint B
没有特别的原因。这是使用Core的第一个项目,所以我想从简单的开始。控制器文件夹需要在wwwroot文件夹中还是在解决方案根目录下? - Brandon
显示剩余12条评论

0

抱歉回复晚了,我没有开启邮件提醒。这是我的web.config文件:

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="true" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
  </system.webServer>
</configuration>

可能是因为您的 Application Pool 正在运行的身份。该身份用户必须在其 PATH 环境变量中具有多个 dnx 路径。因此,最简单的方法是将您的用户名设置为 Application Pool 身份,因为您应该在您的 PATH 环境变量中拥有这些路径。

编辑:在设置 QA 机器时,我们必须创建三个系统环境变量并将它们指向安装 RC1 的用户配置文件。它们分别是:

DNX_HOME - C:\Users\<username>\.dnx

DNX_PACKAGES - C:\Users\<username>\.dnx\packages

DNX_PATH - C:\Users\<username>\.dnx\bin\dnvm.cmd

应用程序池标识用户显然需要访问这些路径。


我昨天解决了!https://dev59.com/gZXfa4cB1Zd3GeqPkdDR#36478567我不得不添加一个Configure1方法来进行一些映射。不幸的是,现在WebAPI在IIS上无法工作,但在express上可以工作。我想这可能与映射有关,但现在不是404错误,而是500错误。如果您愿意提供专业知识,这是我的另一个问题(WebAPI问题)!哈https://dev59.com/o5Xfa4cB1Zd3GeqPk9mQ?noredirect=1#comment60581223_36483610 - Brandon

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