我在使用Visual Studio 2015年我的ASP.NET应用程序的核心发布到IIS 7.5。所有我想要做的就是查看我的wwwroot文件中的一个正常的default.htm页面。一切工作正常,当我使用VS的IIS防爆preSS,但是当我发布是IIS 7.5和指向的Visual Studio上发布创建的wwwroot文件夹的物理路径,我什么也没有,一个空白的屏幕(404)。当我从startup.cs的配置方法中运行默认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 go.microsoft/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版本一起勾选2个选项DNX-CLR-winx86.1.0.0-RC1-UPDATE1下面(删除发布之前,所有现有文件,并编译源文件转换的NuGet包)。这一切都运行在IIS防爆preSS的罚款。这是当我尝试使用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方法。在配置方法,你必须使用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 go.microsoft/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!
推荐答案编辑 - 我解决了它
由于某些原因,你必须有你的配置方法之前,Configure1方法。在配置方法,你必须使用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 go.microsoft/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!
更多推荐
ASP.NET核心404错误在发布到IIS 7.5
发布评论