ASP.NET Core 404 Error When Publishing in IIS 7.5

I am using Visual Studio 2015 to publish my main ASP.NET application for IIS 7.5. All I'm trying to do is look at the regular default.htm page in my wwwroot. Everything works fine when I use VS IIS Express, however, when I publish, it is IIS 7.5 and specify the physical path to the wwwroot folder created by Visual Studio when publishing, I get only a blank screen (404). Which is strange, when I run the default app.run method from the Configure startup.cs method, it works fine:

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

However, when I comment on this, use app.UseDefaultFiles () and app.UseStaticFiles (), I get nothing. Here is 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); } 

Here is 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> 

And here is 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" ] } 

I have already made sure that httpPlatformHandler v1.2 is loaded, and when I publish from VS, I am targeting the DNX version of dnx-clr-winx86.1.0.0-rc1-update1 along with a checkmark for the two options below (delete all existing files before publishing and compile the source files into NuGet packages). Everything works fine in IIS Express. This is when I try to use IIS 7.5, when it starts to get scared.

Any suggestions?

+4
source share
1 answer

Change - I decided it

For some reason, you must have the Configure1 method in front of your Configure method. In the Configure method, you should use app.map (). In addition, I noticed that you should create a new site in your IIS and publish the application in this folder along with setting the physical path to wwwroot. The site name and the name app.map () 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); 

Now I am faced with the problem of my use of WebAPI. Hope this helps!

+3
source

Source: https://habr.com/ru/post/1246494/


All Articles