发布到 IIS 7.5 时出现 ASP.NET Core 404 错误 [英] ASP.NET Core 404 Error When Published to IIS 7.5

查看:31
本文介绍了发布到 IIS 7.5 时出现 ASP.NET Core 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2015 将我的 ASP.NET Core 应用程序发布到 IIS 7.5.我想要做的就是在我的 wwwroot 中查看一个普通的 default.htm 页面.当我使用 VS 的 IIS Express 时一切正常,但是当我发布到 IIS 7.5 并将物理路径指向 Visual Studio 在发布时创建的 wwwroot 文件夹时,我只得到一个空白屏幕 (404).奇怪的是,当我从 startup.cs 的 Configure 方法中运行默认的 app.run 方法时,它运行良好:

I'm using Visual Studio 2015 to publish my ASP.NET Core app to IIS 7.5. All I'm trying to do is view a normal default.htm page within my wwwroot. Everything works fine when I use VS's IIS Express, however when I publish is to IIS 7.5 and point the physical path to the wwwroot folder that Visual Studio created on publish, I get nothing but a blank screen (404). What's weird is when I run the default app.run method from within the Configure method of startup.cs, it works perfectly:

app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });

但是,当我将其注释掉时,使用 app.UseDefaultFiles() 和 app.UseStaticFiles(),我什么也得不到.这是我的 Startup.cs 文件:

However, when I comment that out, use the app.UseDefaultFiles() and app.UseStaticFiles(), I get nothing. Here's my Startup.cs file:

public class Startup
    {
        // 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)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            app.UseIISPlatformHandler();
            //app.UseDirectoryBrowser();
            //app.UseDefaultFiles();
            //app.UseStaticFiles();

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

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

这是我的 web.config 文件:

Here's my web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
  </system.webServer>
</configuration>

这是我的 project.json 文件:

And here's my project.json file:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

我已经确保下载了 httpPlatformHandler v1.2,当我从 VS 发布时,我的目标是 DNX 版本 dnx-clr-winx86.1.0.0-rc1-update1 并选中 2 个选项下面(在发布之前删除所有现有文件,并将源文件编译为 NuGet 包).这一切在 IIS Express 中运行良好.当我尝试使用 IIS 7.5 时,它开始变得时髦.

I've already made sure that I have httpPlatformHandler v1.2 downloaded, and when I publish from VS, I'm targeting DNX Version dnx-clr-winx86.1.0.0-rc1-update1 along with checkmarking the 2 options below (delete all existing files prior to publish, and compile source files into NuGet packages). It all runs fine in IIS Express. It's when I try to use IIS 7.5 is when it starts getting funky.

有什么建议吗?

推荐答案

编辑 - 我解决了

出于某种原因,您必须在 Configure1 方法之前使用 Configure1 方法.在 Configure 方法中,您必须使用 app.map().此外,我注意到您必须在 IIS 中创建一个新站点并将应用程序发布到该文件夹​​,同时设置 wwwroot 的物理路径.站点名称和 app.map() 名称必须匹配.见下文:

For some reason, you have to have a Configure1 method before your Configure method. In the Configure method, you have to use the app.map(). Also, I've noticed that you must create a new site in your IIS and publish the app to that folder along with setting the physical path to the wwwroot. The site name and the app.map() name must match. See below:

        public Startup(IHostingEnvironment env)
        {
        }

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

        public void Configure1(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseIISPlatformHandler();
            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.Map("/appRoot", (app1) => this.Configure1(app1, env, loggerFactory));
        }

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

现在,我遇到了 WebAPI 混乱的问题.希望这会有所帮助!

Now, I'm running into the issue of my WebAPI messing up though. Hope this helps!

这篇关于发布到 IIS 7.5 时出现 ASP.NET Core 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆