1

I have an controller called "AuditoriaController" and at the _Layout.vbhtml I have a action link to this controller:

<li>@Html.ActionLink("Auditoria", "Index", "Auditoria")</li>

When I click at this link at the view I have this error message:

Server Error in '/' Application.

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.

Requested URL: /Auditoria/

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

At the AuditoriaController I have this code:

Public Class AuditoriaController
    Inherits System.Web.Mvc.Controller

    '
    ' GET: /Auditoria

    Function Index() As ActionResult
        Return View(AuditoriaDB.GetAllItems())
    End Function
End Class

Here is my Routes at the RouteConfig.vb

Public Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

    routes.MapRoute( _
        name:="Default", _
        url:="{controller}/{action}/{id}", _
        defaults:=New With {.controller = "EscalaPrevisao", .action = "Index", .id = UrlParameter.Optional} _
    )
End Sub

With other controllers not happen this problem. If I use this url: localhost:4802/Auditoria/Index the error does not happen.

Can anyone help me?

5
  • Please show us your routes. Commented Jan 29, 2013 at 16:14
  • Have you added view Index for this controller? Commented Jan 29, 2013 at 16:16
  • I have the View Index. If I access the View at URL: Auditoria/Index I don't have this problem. Commented Jan 29, 2013 at 16:18
  • 1
    Your code looks and works fine. So something else causing your issue what you haven't show us. Can you post relevant part of the generated html? Are you using any third party component which effects the routing, any custom httphandler/module any JS which manipulates with the links? Commented Jan 29, 2013 at 16:31
  • I'm using only the default JS and HttpHandler/Module from the ASP.NET MVC 4. I don't use third party component, I only use NHibernate and Fluent NHibernate. Do you want to see the Index View HTML? or the _Layout HTML? Commented Jan 29, 2013 at 16:47

5 Answers 5

4

A 404 is returned when the controller class name is not what is expected.

Rename the "Home" default class to "Home1" and you'll see the exact same error. Validate there are no typos... It's almost guaranteed to be that.

Sign up to request clarification or add additional context in comments.

1 Comment

I had another folder called "Auditoria" at the root of the project, so it this error happens. I change the folder name to "AuditoriaDb" and the problem were solved.
2

Go to the Project properties page of the Web project and select the Web tab. In the Start Action section, set it to Specific Page, but leave the textbox empty.

2 Comments

or for me works : Default/Home only keywords/ names not the physical path such as view(folder name)/Default/Home.chtml , the first two keywords do the job exactly which i wonder where it didn't have it set initially and why @junaid set it empty and it does work ... anyways it works for me so thanks + 1 for leading to the source of problem!
well it does not follow this in my iis though... so still have the problem as it applies to the vs2010 development server when in debug not in real life..
0

Try rewriting the URL in the Application_BeginRequest() event in Global.Asax.cs

        protected void Application_BeginRequest()
    {
        var originalPath = HttpContext.Current.Request.Path.ToLower();
        if (originalPath.Equals("/"))
        {
            Context.RewritePath("Controller/Action");
        }

    }

Not an ideal solution but it works as a temporary one.

Comments

0

My controllers's namespace was incorrect (from moving files around). Once I fixed the namespace, all worked.

Comments

0

I Click the red highlighted check box and every thing went OK

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.