kreljm
kreljm

Reputation: 11

problem with routing asp.net

I am fairly new to asp.net and I have a starting URL of http://localhost:61431/WebSuds/Suds/Welcome and routing code

       routes.MapRoute(
            "Default",                                 // Route name
            "{controller}/{action}/{page}",            // URL with parameters
            new { controller = "Suds", action = "Welcome", page = 1 }  // Parameter defaults
        );

        routes.MapRoute(
          "Single",
          "{controller}/{action}",
         new { controller = "Suds", action = "Welcome" }
        );

I am receiving the following error: 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.

Can anyone please help me figure out how to route the beginning url to the controller.

Upvotes: 1

Views: 176

Answers (3)

rob waminal
rob waminal

Reputation: 18419

With the following Routes and Url you have given make sure you have these Methods in your Controller

public class SudsController
{
    public ActionResultWelcome(int? page) 
    {
        return View();
    }
}

Since you have created two routes of the same Action, one with a parameter page and another without. So I made the parameter int nullable. If you don't make your parameter in Welcome nullable it will return an error since Welcome is accepting an int and it will always look for a Url looks like this, /WebSuds/Suds/Welcome/1. You can also make your parameter as string to make your parameter nullable.

Then you should have this in your View Folder

Views
    Suds
        Welcome.aspx

If does doesn't exist, it will return a 404 error since you don't have a corresponding page in your Welcome ActionResult.

If all of this including what BritishDeveloper said. This should help you solve your problem.

Upvotes: 0

BritishDeveloper
BritishDeveloper

Reputation: 13349

Route tables are searched on a first come first served basis. Once an appropriate match is found any following routes will be ignored.

You need to add "WebSuds/{controller}/{action}" and put it above the default route. The most specific routes should always go above the more generic ones.

Upvotes: 1

Bryan
Bryan

Reputation: 2870

Because the first part of your URL is WebSuds, the framework is trying to map the request to WebSudsController instead of SudsController. One thing you can try is to change the url parameter of your route to "WebSuds/{controller}/{action}".

Upvotes: 1

Related Questions