Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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.

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.

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

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top