ASP.NET Core 404 Error When Published to IIS 7.5

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!");
            });

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

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>

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"
  ]
}

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.

Any suggestions?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Edit – I solved it

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);

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x