Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have an MVC application in .NET 3.5 framework which is hosted in IIS 7. I have created the application in the root of the IIS 7. My application works fine when i try to access the by the path "http://localhost". But if i try to access any file present under the "Views" folder i get the follwoing error.

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

I have tried all ways and means to fix this bug but in vain. Would be grateful if anybdy can help me to identify the probelm.

Thanks

share|improve this question

5 Answers 5

In ASP.NET MVC you don't browse to your view files directly. You have to use the routes that are setup in your site's Application_Start() event.

For example, a new ASP.NET MVC project adds this route by default in global.asax:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",                           
    new { controller = "Home", action = "Index", id = "" }  
);

It also adds a default controller and action:

public class HomeController : Controller {
  public ActionResult Index() {
    ViewData["Message"] = "Welcome to ASP.NET MVC!";
    return View();
  }
}

And a View under Views/Home named Index.aspx.

Instead of using the address http://mysite.com/Views/Home/Index.aspx you would use http://mysite.com/Home/Index

You can learn more about routing here: http://www.asp.net/learn/mvc/#MVC_Routing

share|improve this answer

I want to add something: I am pretty sure that what you actually need is to add the .ASPX reditection on your IIS server. If you are using IIS6, this can be done with the following steps:

  1. Right click your site
  2. Go to Properties
  3. Home Directory tab and then select Configuration
  4. On the "Wild Card Application Maps", please add the path to your .ASPX. Lastly, please untick the "Verify that file exists".

Without the steps above, your ASP.NET MVC will not work properly. I have had this experience before and my current host, ASPHostCentral, advised me those steps above :)

Good luck!

share|improve this answer
    
+1. This is likely the problem. Refer to these instructions: haacked.com/archive/2008/11/26/…... Scroll down to "IIS6 Extension-less URLs" –  p.campbell Feb 8 '10 at 21:53
  1. Right click your site
  2. Go to Properties
  3. Click the Home Directory tab and then select Configuration
  4. On the "Wild Card Application Maps", please add the path to your .ASPX. Lastly, please untick the "Verify that file exists".
share|improve this answer

I have found a new reason for this error: If you are using Resharper it is suggesting to change eventhandler name but if you click to yes it is not changing the event name of the object under the Global.asax file. I havent seem the object in the framework but it is perceptible

share|improve this answer

You can see those files if you really must - for example if they're plain .html files - with an Ignore route:

routes.IgnoreRoute("Views/{name}.html");

That would allow you to browse directly to any .html file living in the Views folder, without defining routes, controllers, etc. It's pretty nice how easily the Routes system gets in and out of the way depending on what you want out of it.

You can learn Routes in 4 steps here: http://www.asp.net/learn/mvc/#MVC_Routing

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.