2

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

5 Answers 5

4

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

2

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!

1
1
  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".
1

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

0

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

You must log in to answer this question.