locked
Deployed MVC 5 app cannot find views RRS feed

  • Question

  • User-734459410 posted

    I have been getting this error:


    The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/Home/Index.aspx
    ~/Views/Home/Index.ascx
    ~/Views/Shared/Index.aspx
    ~/Views/Shared/Index.ascx
    ~/Views/Home/Index.cshtml
    ~/Views/Home/Index.vbhtml
    ~/Views/Shared/Index.cshtml
    ~/Views/Shared/Index.vbhtml


    I have verified that the view is in fact in the correct locations.  The only difference between my MVC 5 app and a default (out of the box ones) is that I'm using Areas.
    But it can't even find the canned/OOB default view for the Home Controller (which would be found in Views/Home/Index.cshtml).

    None of the default views or controllers have been changed.  Any ideas on what could be causing this?  Is there a setting in IIS that I need to tell it use Routing?

    I'm using Server 2012 R2 Standard which I think has IIS 8.0 installed.

    Wednesday, December 20, 2017 8:05 PM

Answers

  • User-734459410 posted

    OK so here is my solution to this issue if people are having this same problem (this worked in my case, at least, after successful verification that it wasn't a problem with my code or the MVC application itself, but rather IIS being picky....)

    So, I found that when you deploy one site, and then have to remove and re-deploy your site, completely remove the folder in which the original site was stored and create a new folder (preferably with a different name so to make sure that Windows and IIS see it as a different folder).  Then go back through and set up a new website for your application.  The other problem I had is I wasn't binding the IP address of the server to the Website, which may have also caused this issue as well too (so the folders thing may not have actually fixed the problem).  Either way, by doing both of those things, I was able to successfuly remove the old site, update it, and re-upload/deploy to the server.

    Also, make sure that IUSR has access to the folder and it's contents (read/write/execute).  I also create a separate admin account that I use for authorization in the Setup process when creating a new IIS site.  Now, this user may not necessarily have to be an Admin, but probably at least needs read/write/execute permissions on the folder holding your website and it's files.  Since my application is an internal Intranet application, it will only be run and be accessible from our internal network so creating and using an Admin account wasn't as much of a concern to me, but in a production environment where you may be deploying to an actual web server that outside visitors may be using, you may not want to use an Admin account for the Website.

    It gave me some headaches at first (trying to remove and re-deploy the site), but after doing these two things, should help prevent the error message where it can't find Index or it's master (referring to that IIS can't find the appropriate views).  If people need clarification in my steps, please PM me.

    I cann't say for sure what causes this problem/ why it happens, but this is the "workaround" that I've found that seems to be repeatable (both getting the error and then resolving it) and seems to work so far.  It's quite a few steps and there are probably easier faster ways to update your site (particularly the binaries, should you need to recompile your site) but this is the workaround I have found and used and so far its been working.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 20, 2017 11:42 PM

All replies

  • User1564875471 posted

    Is this issue happening only when deploying the app ? or all the time ? Based on the errors, the areas doesn't seem to be registerd in your app. Please verify that you correctly register the areas. Verify you have the following line of code in the Application_Start event handler:

    AreaRegistration.RegisterAllAreas();

    Wednesday, December 20, 2017 8:37 PM
  • User-734459410 posted

    This has only happened when the app is deployed to the server.  Does not occur during testing on the development machine.

    I am registering the areas using this code:

      public class OMAreaRegistration : AreaRegistration 
        {
            public override string AreaName 
            {
                get 
                {
                    return "OM";
                }
            }
    
            public override void RegisterArea(AreaRegistrationContext context) 
            {
                context.MapRoute(
                    "OM_default",
                    "OM/{controller}/{action}/{id}",
                    new { controller = "SalesOrders" action = "OpenOrderList", id = UrlParameter.Optional }
                );
            }
    
      }

    This is for the Areas, but I can't even get the default Home controller to load the default Index view, which I did verify, is in the correct location.  No
    changes were made to the Home Controller.  The only change I made to the Index view in the home controller was modify the links at the top
    (Home, About, Contact) to add links to the Areas within the app (in this case, Sales Orders).

    I will also add that I'm deploying to a folder, and then copying the folder over to the server, and then adding it as an Application to the Default website in IIS (this is an intranet application so it's only for internal use for our company).  I've also double checked permissions and other settings in IIS, and they pretty much match my other Application which is being served under the same Default Website (the only difference is that that application doesn't use Areas).  That one works fine, so I'm thinking it's maybe a setting in IIS?

    Wednesday, December 20, 2017 8:44 PM
  • User1564875471 posted

    Please verify the following:

    Step 1: Open the "Global.asax" file.

    Step 2: Check the Application_Start() method and make sure it's calling the following function:

    AreaRegistration.RegisterAllAreas();

    Wednesday, December 20, 2017 9:02 PM
  • User-734459410 posted

    Yes it is calling AreaRegistration.RegisterAllAreas();

    I tried to deploy an out-of-box MVC application (no customization, just creating in VS and then build and deploy using the Deploy to Folder method).   I get the same result in that IIS cannot find the views so I'm starting to think this may be an IIS (or Application) configuration issue, and not an issue with my code or the solution itself.

    Wednesday, December 20, 2017 9:22 PM
  • User1564875471 posted

    Also try to check if you have the correct .NET framework version installed on the server and make sure the IIS user has a permission on the app directory.

    Wednesday, December 20, 2017 9:35 PM
  • User-734459410 posted

    OK, so after playing around with IIS a bit, I was able to get it to work (although it seems to be a little slower but that could be because this project is significantly larger than the existing one I have on there).  All I did was just create an entirely new website space in IIS, rather than adding a another Application to the existing website (which was the Default Website which is configured by default within IIS). 

    I am staring to wonder if having multiple Applications within the same site, that are using MVC, that may cause conflicts (maybe the routing engine doesn't know which Application to look for Views maybe?  Even though each Application was in its own folder on the server.)

    So in all, I got it to work.  I just need to figure out why it's a bit slow.  It is a database application that uses two different databases running on two different DB engines so that could maybe be part of it.  Plus one of the databases is located on another server in the same building....

    Wednesday, December 20, 2017 9:52 PM
  • User-734459410 posted

    OK so here is my solution to this issue if people are having this same problem (this worked in my case, at least, after successful verification that it wasn't a problem with my code or the MVC application itself, but rather IIS being picky....)

    So, I found that when you deploy one site, and then have to remove and re-deploy your site, completely remove the folder in which the original site was stored and create a new folder (preferably with a different name so to make sure that Windows and IIS see it as a different folder).  Then go back through and set up a new website for your application.  The other problem I had is I wasn't binding the IP address of the server to the Website, which may have also caused this issue as well too (so the folders thing may not have actually fixed the problem).  Either way, by doing both of those things, I was able to successfuly remove the old site, update it, and re-upload/deploy to the server.

    Also, make sure that IUSR has access to the folder and it's contents (read/write/execute).  I also create a separate admin account that I use for authorization in the Setup process when creating a new IIS site.  Now, this user may not necessarily have to be an Admin, but probably at least needs read/write/execute permissions on the folder holding your website and it's files.  Since my application is an internal Intranet application, it will only be run and be accessible from our internal network so creating and using an Admin account wasn't as much of a concern to me, but in a production environment where you may be deploying to an actual web server that outside visitors may be using, you may not want to use an Admin account for the Website.

    It gave me some headaches at first (trying to remove and re-deploy the site), but after doing these two things, should help prevent the error message where it can't find Index or it's master (referring to that IIS can't find the appropriate views).  If people need clarification in my steps, please PM me.

    I cann't say for sure what causes this problem/ why it happens, but this is the "workaround" that I've found that seems to be repeatable (both getting the error and then resolving it) and seems to work so far.  It's quite a few steps and there are probably easier faster ways to update your site (particularly the binaries, should you need to recompile your site) but this is the workaround I have found and used and so far its been working.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 20, 2017 11:42 PM