1
votes

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. - SLaks
Have you added view Index for this controller? - Bhushan Firake
I have the View Index. If I access the View at URL: Auditoria/Index I don't have this problem. - Pedro Galinatti
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? - nemesv
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? - Pedro Galinatti

5 Answers

2
votes

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.

2
votes

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.

0
votes

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.

0
votes

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

0
votes

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