views:

797

answers:

8

I'm having problems publishing my MVC project. When I do publish and upload everything to web server I get this:

[InvalidOperationException: The view 'Index' or its master could not be found. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx]

Weird thing is that Index.aspx exists in ~/Views/Home/, but IIS cannot find it there. If I copy entire project to web server and let asp.net compile it on the fly it works like a charm.

My routing code:

  routes.MapRoute( _
    "Default", _
    "{controller}/{action}/{id}", _
    New With {.controller = "Home", .action = "Index", .id = ""} _
  )

  routes.MapRoute("Root", "", New With {.controller = "Home", .action = "Index", .id =""})

I'm using IIS7 on Windows 2008 Web server. ASP.NET MVC 1.0, Visual Studio 2008. I've tried it local with IIS7 on Windows 7 - same error.

UPDATE - I've created a new MVC project, and added all my files to it. Referencing projects have been referenced as compiled binaries. After publishing "only files needed to run application" I get the same error.

A: 

Check if the masterpage of Index.aspx exists also.
If you are using "web site" project try to choose the "Allow this precompiled site to be updatable" option when publishing the site.
If you are using "web application" project try to choose the "Copy - All project files" option on publish.

Try also to copy only the views. I think that ASP.NET MVC projects when precompiled doesn't work well because of the marker files (the .aspx and ascx files are replaced with marker files on precompilation).

If you are using IIS 6 or below check the deployment guide for asp.net mvc - http://www.asp.net/learn/mvc/tutorial-08-cs.aspx.

Branislav Abadjimarinov
Using "Copy - All project files" works, but this is the same as copying all the source code on server myself, besides the precompilation of course. I still get .svn folders that just isn't acceptable
Vnuk
I have a feeling that the problem is that asp.net mvc doesn't work with marker files in precompiled projects. I haven't figured out why yet.
Branislav Abadjimarinov
Those files that he claims can't find aren't marker files. All views are in their source versions (aspx or ascx), not markers, even in published "Only files needed to run this application" mode.
Vnuk
A: 

1) Check if your Index.aspx included in the project. (exists in publish result folder) Locally at VS it may works, but on publish it will not be copied.

2) Check if Views/web.config file included in the project - it affects the was ASP.NET MVC compile the Views.

3) Check if Index.aspx has Build Action = Content (in properties window).

Lion_cl
1. yes it is2. yes it is3. yes it does
Vnuk
It's always happens even if you create new project from scratch?If not - check the difference.
Lion_cl
Well that's the thing. I have several MVC projects on my machine, and it only happens on this project. I've tried to find differences but found none, and I'm still baffled why this doesn't work.
Vnuk
Try to recreate project file .csproj (create new project) and put all current files into new one. This may fix. Also, check the new project and old project text(xml) contents.
Lion_cl
A: 

Check the rights on the server, make sure the asp.net worker process has the correct rights on the views folder, sub-folders, and files.

also, is your IIS instance running in Classic or Integrated Pipeline mode?

Paul
A: 

Try appending .aspx to the controller part of the URL, for example http://myserver/appname/Index.aspx/Home - if I remember rightly, IIS7 has issues with MVC apps displaying the control/action urls properly unless you a) refer to the controller part using the .aspx suffix b) tweak a setting on the server, but this affect all apps on that server c) load an addon I found a good article on this but I can't find it, search around and I'm sure you will find it yourself if the .aspx solution isn't good for you

Mad Halfling
That does not make sense (appending .aspx) beacause in Views folder web.config maps all direct requests to System.Web.HttpNotFoundHandler. This is not server wide problem but project specific. It doesn't work on my local IIS7 and on my hosting server where numerous ASP.NET MVC apps work without any problems.
Vnuk
I know it doesn't make sense and that's what I thought, but there is a version of IIS that doesn't work out-of-the-box with ASP.NET MVC and I'm sure it's 7. I have hit this problem myself on the company that I am working for's server and that was the solution that I've had to use as I can't change the deployment server's config. Have you tried it? It will at least tell you if you have this issue and need to find out if the alternative fixes are viable. If you have existing MVC apps working then that's fine, but thought I'd let you know about a problem I had.
Mad Halfling
@Madits IIS 6 that does not work out-of-the-box seehttp://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
marc.d
As I said, I was sure it was 7, and I'm sure our server (I haven't got direct access to it, so I couldn't check to be sure, but I checked my e-mails and they seem to confirm this) is 7, but I could be wrong. The simple test I suggested would have confirmed whether or not that issue was occurring so I thought it might help if this was the case - just thought I'd add in something that might be useful.
Mad Halfling
A: 

Removed the previous link, this one explains it a bit better http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis7/.

If you're developing using the local asp.net webdev server, you must remove some of the HttpHandlers and HttpModules and then add them back to the section. This tells IIS7 to run those in integrated mode. This is needed when deploying your app to an IIS 7 server including for MVC. See below as a reference example:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ScriptModule" />
      <remove name="UrlRoutingModule" />
<add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" />
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
<handlers>
  <remove name="WebServiceHandlerFactory-Integrated" />
  <remove name="ScriptHandlerFactory" />
  <remove name="ScriptHandlerFactoryAppServices" />
  <remove name="ScriptResource" />
  <remove name="MvcHttpHandler" />
  <remove name="UrlRoutingHandler" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
          <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </handlers>
      </system.webServer>

Hope that helps,

Eddy

PS. Old link http://www.asp.net/(S(ywiyuluxr3qb2dfva1z5lgeg))/learn/mvc/tutorial-08-cs.aspx

Dax70
Sorry but this has nothing to do with my problem. I'm running on IIS7 with integrated mode, and my requests are handled by MVC which has problem finding views.
Vnuk
On the link I posted, the Index view is not found when the config is not properly configured under IIS7 integrated mode. I just thought it was perhaps worth a look.
Dax70
Your web.config snippet looks like you've copied it from my web.config, execpt for the part where your snippet is referencing asp.net mvc 2.0 (I'm still on 1.0).
Vnuk
A: 

What is the exact call to View("Index", ...) you are using. Maybe the second parameter is a string - in this case another overload of the View- method is used, where the second parameter is the name of the master page.

Solution: Just cast the second parameter as object.

ollifant
I'm a bit puzzled by your answer. Exact call to view is Return View(), with no parameters. I've tried specifying both view and master, but that just gave a two new "not found files" on error screen mentioned for specified master file.
Vnuk
Ok, than you have a different problem. I once stumbled about the error of passing a view data which was a string. In that case the string was used as the filename of the master page.
ollifant
A: 

Since it works when copying the entire project, perhaps you aren't copying all the files that you need? Make sure any non-standard references are set to Copy Local and use the built-in Publish feature under the Build menu to get the files needed for the project to run.

Clownish Carnage
+1  A: 

Solution to this problem is as bizarre as it's manifestation.

My master code behind file was declared as Partial instead of Public and my master definition was

<%@ Master Language="VB" Inherits="SiteFrontPageMaster"  ClassName="SiteFrontPageMaster" CodeFile="SiteFrontPageMaster.Master.vb"  %>

and it should have been

<%@ Master Language="VB" Inherits="mymvcproject.SiteFrontPageMaster" CodeBehind="SiteFrontPageMaster.Master.vb" %>

Why was something acceptable for Cassini and not for IIS is beyond my ability to understand. I just hope that this answer saves someone else my amount of headache.

Vnuk