IIS MVC web app gets 404.0 error when opening first view page

Jay Gunderson 0 Reputation points
2025-02-14T17:50:30.9833333+00:00

I built an MVC web application (about a dozen view pages) that is working fine when run from the VS.net 2019 designer IIS Express, but when I deploy the app to local IIS and run it, I get error...

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

After weeks of checking every issue I can find, I have to ask for help form the folks here - what am I missing? Here are the steps my app uses to get its first web page to be reached...

I have index.html at the myApp home directory which invokes the first view page...

var host = window.location.host;

var protocol = window.location.protocol; 

var url = protocol + "//" + host + "/myAppLogin/Login"; 

//alert("url: " + url); 

window.location.replace(url); 

Here is my RouteConfig.cs...

namespace myApp

{

public class RouteConfig 

{ 

    public static void RegisterRoutes(RouteCollection routes) 

    { 

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

        routes.IgnoreRoute("");  



        routes.MapRoute( 



            name: "Default",  

            url: "{controller}/{action}/{id}",                

            defaults: new { controller = "myAppLogin", action = "Login", id = UrlParameter.Optional } 

        ); 

    } 

} 

}

The myApp properties in VS.net designer shows start action specific page with index.html shown.

I copy the entire project over to C:/inetput/wwwroot

In inetMgr I startup myApp and check bindings and settings, all looks ok on port 80 (default Web Site shut down)

Next I issue this in my web browser - http://localhost/myApp/index.html which gives error...

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

the 404.0 error page shows RouteConfig.cs did its job correctly...

Requested URL http://localhost:80/myAppLogin/Login

Physical Path C:\inetpub\wwwroot\myApp\myAppLogin\Login Logon

Method Anonymous

Logon User Anonymous

Some other settings that might be appropriate...

Windows 11 pro IIS version 10.0.26100.1 DefaultAppPool .net CLR version v4.0 identity is NetworkService

myApp .net CLR version is v4.0 and identity is NetworkService

myApp web site has physical path C:\inetpub\wwwroot\myApp defaultAppPool and pass-through authentication.

Thanks for any help.

Jay

Developer technologies | ASP.NET | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 79,101 Reputation points Volunteer Moderator
    2025-02-16T16:38:57.93+00:00

    You appear to configured you website as an application directory rather than root site. If the url to the index is:

    http://localhost/myApp/index.html

    then the login route is:

    http://localhost/myApp/myapplogin/login

    Your JavaScript needs to add the application directory name part of the path. A common approach is to set the base href in document.

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    Then in JavaScript do:

    window.location.replace(“/myapplogin/login”);
    
    0 comments No comments

  2. Danny Nguyen (WICLOUD CORPORATION) 725 Reputation points Microsoft External Staff
    2025-07-16T08:45:17.7433333+00:00

    Hi Jay,

    Based on your description and the responses you've received, the issue is that your MVC application is deployed as a sub-application under IIS (at /myApp/) rather than as the root site, but your routing and JavaScript aren't accounting for this application path.

    Your JavaScript is constructing URLs that don't include the application directory path (/myApp/). When you access http://localhost/myApp/index.html, your JavaScript redirects to http://localhost/myAppLogin/Login, but it should redirect to http://localhost/myApp/myAppLogin/Login.

    Here's how you can fix this:

    Option 1: Fix the JavaScript

    Update your JavaScript to include the application path:

    var host = window.location.host;
    var protocol = window.location.protocol;
    var pathname = window.location.pathname;
    
    // Extract the application path (e.g., "/myApp")
    var appPath = pathname.substring(0, pathname.lastIndexOf('/'));
    
    var url = protocol + "//" + host + appPath + "/myAppLogin/Login";
    window.location.replace(url);
    

    Option 2: Use Base Href

    Add a base href to your index.html:

    <head>
        <base href="/myApp/" />
        <!-- other head content -->
    </head>
    

    Then simplify your JavaScript:

    window.location.replace("/myAppLogin/Login");
    

    Option 3: Deploy as Root Site

    Instead of deploying to C:\inetpub\wwwroot\myApp, deploy directly to C:\inetpub\wwwroot and configure your site as the root site rather than a sub-application.

    Hope this helps.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.