Paulie
Paulie

Reputation: 131

404 after changing routes in ASP NET MVC application

I had working routes on my app that looked like this:

            routes.MapRoute(
            name: "Category",
            url: "{name}-c{categoryId}",
            defaults: new { controller = "Products", action = "Index", name = "ErrorName" },
            namespaces: new[] { "B2B.Controllers" });

        routes.MapRoute(
            name: "InfoPage",
            url: "{name}-i{id}",
            defaults: new { controller = "InfoPages", action = "Details", name = "ErrorName" },
            namespaces: new[] { "B2B.Controllers" });

I've changed the dash (-) to the hash (#) because spaces are changed in url to dashes.

 url: "{name}#c{categoryId}",
 url: "{name}#i{id}",

Now I've this same routes with only this one char changed and I get 404 on urls like this:

siteadess:1234/1.0.1-Podstawowa%23c4

I've also tried to change hash to under score and it didn't worked either.

Upvotes: 0

Views: 82

Answers (2)

Paulie
Paulie

Reputation: 131

The main reason of routing didn't worked were dots in the url adress.

siteadess:1234/1.0.1-Podstawowa%23c4

After removing dots everything works perfect! As sugested by others I've also replaced hashtag with underscore.

Upvotes: 0

clifford.duke
clifford.duke

Reputation: 4040

You cannot use hashes(#) in a URL route because anything after the hash is never sent to the server.

So your route /{name}#c{categoryId} will never get hit because the closest that the server will ever see is /{name}

Upvotes: 1

Related Questions