【问题标题】:Why does my ASP.NET 5 Application Not Run On IIS 7.5?为什么我的 ASP.NET 5 应用程序不能在 IIS 7.5 上运行?
【发布时间】:2016-04-05 17:50:41
【问题描述】:

我正在使用 IIS 7.5 运行 ASP.NET 5 (Core)。我已经安装了 httpPlatformHandler 并将站点的物理路径(在 IIS 中)设置为我从 Visual Studio 2015 发布的 wwwroot 文件夹。我得到的只是空白的连续加载页面。我很确定我已经正确连接了所有东西。此外,如果我从 Configure 方法中取消注释掉 app.Run 语句并注释掉 app.UseIISPlatformHandler、app.UseDefaultFiles、app.UseStaticFiles 和 app.UseMVC,它会正常加载。

我的代码如下。我不知道此时还能做什么。有什么建议?如果需要任何其他代码 sn-ps,请告诉我。

Startup.cs(配置方法)

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 not found。还有什么建议吗?

添加我的完整 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);

【问题讨论】:

  • 您是否收到任何错误消息?您在事件查看器中看到什么了吗?
  • 否定。我得到空白的连续加载页面。完全没有错误
  • 以前报错,后来下载了httpplatformhandler,现在就这样了。
  • 什么版本的平台处理程序?为此,您需要 1.2 版(或更高版本)。
  • 我下载了 v1.2 但是我要去哪里仔细检查版本?

标签: c# asp.net asp.net-mvc iis


【解决方案1】:

您是否查看过 IIS 日志以查看是否向 IIS 发出了请求?

您也可以尝试在 Startup 类的 Configure() 方法中定义的每个中间件模块之间放置一个简单的中间件模块。您的中间件可以将消息写入 Windows 事件日志,说明它在 Http 管道中的位置以及响应正文的内容。有点像设置警报来调试 Javascript。这至少会让你知道它在哪里挂断或清除响应正文。

我在 github 上发布了一个非常易于理解的演示,演示了如何通过三个简单的步骤创建中间件。点击here 进入该演示。

更新: 尝试将您的 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”。现在,我不知道这意味着什么。
  • 这台机器与您在 Visual Studio 中运行时成功显示页面的机器是否不同?
  • 不。同一台机器。实际上,我现在正在使用 VS 来处理它。太奇怪了。刚刚对该错误代码进行了一些研究,很明显,当我的初创公司被调用时,它是某种工作人员崩溃了。我将在上面添加其余的 startup.cs 代码
  • 我正在尝试更新我的答案。您正在运行 ASP.NET 5 RC1 对吗?
  • 我刚刚看到了额外的 cmets,您说您只是在尝试访问静态 index.html 文件。我认为如果您使用带有控制器的 index.cshtml 文件,您的所有问题都会消失。您是否有不想使用 MVC 的特殊原因?
【解决方案2】:

抱歉耽搁了,我没有打开电子邮件提醒。这是我的 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>

它可能是您的应用程序池在其下运行的标识。身份用户必须在其 PATH 环境变量中包含许多 dnx 路径。因此,将您的用户名设置为应用程序池标识是最简单的,因为您的 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

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

【讨论】:

  • 我昨天解决了! stackoverflow.com/questions/36460967/… 我必须为某些映射添加一个 Configure1 方法。不幸的是,现在 WebAPI 在 IIS 上不起作用,但它在 express 上起作用。我认为它与映射有其他关系,但现在不是 404 错误,而是 500 错误。如果您想提供专业知识,这是我提出的另一个问题(WebAPI 问题)!哈哈stackoverflow.com/questions/36483610/…
猜你喜欢
  • 1970-01-01
  • 2012-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-23
  • 2011-09-27
  • 2010-12-28
  • 1970-01-01
相关资源
最近更新 更多