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

时间:2022-07-19 03:34:14

I'm running ASP.NET 5 (Core) with IIS 7.5. I've already installed httpPlatformHandler and set the physical path of the site (in IIS) to the wwwroot folder that I published from visual studio 2015. All I get is the blank continuous loading page. I am pretty sure I have everything wired up correctly. Also, it loads up fine if I uncomment out the app.Run statement from within the Configure method and comment out the app.UseIISPlatformHandler, app.UseDefaultFiles, app.UseStaticFiles and app.UseMVC.

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

My Code is below. I don't know what else to do at this point. Any suggestions? If any other code snippets are needed, let me know.

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

Startup.cs (Configure method)

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" />

New Edit. I've updated my folder structure to MVC (using Controllers, Views, etc) and I've changed the Configure method a bit. Now it loads a blank screen and the console is logging a 404 not found. Anymore suggestions?

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

Adding my full Startup.cs:

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

2 个解决方案

#1


2  

Have you looked at the IIS logs to see if the request is even making to IIS?

您是否查看过IIS日志以查看该请求是否正在向IIS发送?

You can also try putting a simple middleware module inbetween each middleware module defined in the Configure() method of class Startup. Your middleware can write a message to the Windows event log stating where it's at in the Http pipeline and the contents of the response body. Kind of like putting in alerts to debug Javascript. That will at least let you know where it's hanging up or clearing the response body.

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

I posted a very easy to understand demo on github that demonstrates how to create middleware in three easy steps. Click here to go to that demo.

我在github上发布了一个非常容易理解的演示,它演示了如何通过三个简单的步骤创建中间件。点击此处转到该演示。

UPDATE: Try changing your Configure() method to the code below (put in your own route if mine isn't correct for your setup).

更新:尝试将Configure()方法更改为下面的代码(如果我的设置不正确,请放入您自己的路径)。

app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();

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

#2


0  

Sorry for the delay, I didn't have email alerts turned on. Here's my web.config

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

It could be the identity that your Application Pool is running under. The identity user has to have a number of dnx paths in its PATH environment variable. So it's easiest just to set your username as the Application Pool identity because you should have those paths in your PATH environment variable.

它可能是您的应用程序池运行的标识。身份用户必须在其PATH环境变量中具有多个dnx路径。因此,将您的用户名设置为应用程序池标识是最简单的,因为您应该在PATH环境变量中包含这些路径。

EDIT: When we setup our QA machine we had to create three System environment variables and point them to the user profile that installed RC1. Those are:

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

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

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

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

And the Application Pool identity user obviously needs to have access to those paths.

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

#1


2  

Have you looked at the IIS logs to see if the request is even making to IIS?

您是否查看过IIS日志以查看该请求是否正在向IIS发送?

You can also try putting a simple middleware module inbetween each middleware module defined in the Configure() method of class Startup. Your middleware can write a message to the Windows event log stating where it's at in the Http pipeline and the contents of the response body. Kind of like putting in alerts to debug Javascript. That will at least let you know where it's hanging up or clearing the response body.

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

I posted a very easy to understand demo on github that demonstrates how to create middleware in three easy steps. Click here to go to that demo.

我在github上发布了一个非常容易理解的演示,它演示了如何通过三个简单的步骤创建中间件。点击此处转到该演示。

UPDATE: Try changing your Configure() method to the code below (put in your own route if mine isn't correct for your setup).

更新:尝试将Configure()方法更改为下面的代码(如果我的设置不正确,请放入您自己的路径)。

app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();

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

#2


0  

Sorry for the delay, I didn't have email alerts turned on. Here's my web.config

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

It could be the identity that your Application Pool is running under. The identity user has to have a number of dnx paths in its PATH environment variable. So it's easiest just to set your username as the Application Pool identity because you should have those paths in your PATH environment variable.

它可能是您的应用程序池运行的标识。身份用户必须在其PATH环境变量中具有多个dnx路径。因此,将您的用户名设置为应用程序池标识是最简单的,因为您应该在PATH环境变量中包含这些路径。

EDIT: When we setup our QA machine we had to create three System environment variables and point them to the user profile that installed RC1. Those are:

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

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

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

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

And the Application Pool identity user obviously needs to have access to those paths.

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