3

I'm struggling to get my ASP.Net core 1 (asp.net 5 / MVC 6) app running within IIS on my webserver. I've followed the guides and done the following on the server

  • Install ASP.Net 5 via get.asp.net
  • Install HttpPlatformHandler 1.2

I've checked that I can run dnx on the server and that the compiled bits are 64 bit and that the application pool is "No Managed Code" and running as 64 bits.

I can run the app on the webserver by running web.cmd and navigating to http://localhost:5000 (or whatever port), however when I try and setup the app as an application within the Default Website and browse to it (e.g. http://localhost/MyMVC6App) I get a 404 error. I've checked that the physical path is pointing to /MyMVC6App/wwwroot. I've also checked that the webserver/handlers section is unlocked.

I've also created a vanilla ASP.Net 5/Core 1 app and get the same 404 error on 2 different servers!

Here is my configure method:

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIISPlatformHandler();

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

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

Any ideas?

9
  • 1
    I've also just found that I can run the app if I create a new website (not web application) and host it as the only web application. However as I have other web apps (MVC 5 and below) I can't do this as I would need to run the new website on a different port. Commented Feb 22, 2016 at 11:46
  • Can you confirm when you try to access the URL, does the IIS AppPool start dnx.exe? If it's not then it means the issue is with the HttpPlatform config in your web.config file. The path in web.config uses relative paths I think. If it is starting dnx.exe and it dies soon after you should enable stdoutLogEnabled="true" in httpPlatform config to find out why. Commented Feb 22, 2016 at 15:31
  • info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0] User profile is available. Using 'C:\Windows\system32\config\systemprofile\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. Hosting environment: Production Now listening on: localhost:8465 Application started. Press Ctrl+C to shut down. info: Microsoft.AspNet.Hosting.Internal.HostingEngine[1] Request starting HTTP/1.1 GET localhost/Extranet info: Microsoft.AspNet.Hosting.Internal.HostingEngine[2] Request finished in 0.0656ms 404 Commented Feb 23, 2016 at 9:14
  • 1
    Could you also paste in your configure method? I will see if I can reproduce on my end ... Just noticed you are running this as an app on IIS ... They have said that's a known thing... But Add your MVC6app as the base for routes ... Like /MVC6APP/{controller=Home}/... Commented Feb 24, 2016 at 16:10
  • 1
    Holy Moly - if I change my route template to Extranet/{controller=Home}/{action=Index}/{id?}"); it works - the css is screwed but it works - how come!? Commented Feb 24, 2016 at 16:29

1 Answer 1

1

The easiest way to resolve this would be to add the IIS Application name as the base of your route in MVC if your static files are hosted out of the ASPNET Core app.

Another way would be by adding a simple middleware class to strip out the IIS application name and make the request look transparent to any module below it. I havent tested the code below but:

using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;

namespace MyMVC6App
{
    // You may need to install the Microsoft.AspNet.Http.Abstractions package into your project
    public class RemoveIISAppNameMiddleware
    {
        private readonly RequestDelegate _next;

        public RemoveIISAppNameMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public Task Invoke(HttpContext httpContext)
        {
            var newRequestPath = new PathString();
            var requestPathToIgnore = new PathString("/MyMVC6App");

            if (httpContext.Request.Path.StartsWithSegments(requestPathToIgnore))
            {
                httpContext.Request.Path.StartsWithSegments(requestPathToIgnore, out newRequestPath);
                httpContext.Request.Path = newRequestPath;
            }
            return _next(httpContext);
        }
    }

    // Extension method used to add the middleware to the HTTP request pipeline.
    public static class RemoveIISAppNameMiddlewareExtensions
    {
        public static IApplicationBuilder UseRemoveIISAppName(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<RemoveIISAppNameMiddleware>();
        }
    }
}

and then in your configure method after app.UseIISPlatformHandler() you would call app.UseRemoveIISAppName(). In this case you wouldn't need to have any additional path in MVC routes.

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried the above method and also the method outlined in damirscorner.com/blog/posts/… Both enable me to get a hit on the page, but all the css and script links no longer work. I'm trying to use Fiddler to work through it and find a url that works but I'm not having any luck at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.