Including hash values in ASP.NET MVC URL routes

asp.net MvcRoutes

asp.net Mvc Problem Overview


I need to implement hash value i.e the Url should look like this:

>/home/index/#create

For this have added a route:

routes.MapRoute(
    "Default",    // Route name
    "{controller}/{action}/#{detail}",    // URL with parameters
    new { controller = "Login", action = "LogIn",  detail  =""}  // Parameter defaults
);

On accessing /home/index/#create, it is redirecting me to the default route.

How can this be done?

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

As stated there is no way to do this using routing. The only possible solution is to append the # fragment to your url when redirecting in the actions of your controller. Eg.

return Redirect(Url.Action("Index", "Home") + "#create");

Solution 2 - asp.net Mvc

You cannot fetch the value after the # symbol on the server simply because this value is never sent to the server. Only client side javascript has access to this so defining routes with hash doesn't make much sense.

Solution 3 - asp.net Mvc

When a browser makes a request for a URL, it does not send anything after a hash to the server. This route may enable you to generate route URLs containing the hash value but there is no way to do anything server-side when the user navigates to such a URL. That's just the way the web works...

Solution 4 - asp.net Mvc

OAuth 2.0 Implicit Flow

If this has to do with OAuth 2.0 Implicit Flow, you should use Authorization Code Grant instead.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfacebookView Question on Stackoverflow
Solution 1 - asp.net MvcRory McCrossanView Answer on Stackoverflow
Solution 2 - asp.net MvcDarin DimitrovView Answer on Stackoverflow
Solution 3 - asp.net MvcRobert LevyView Answer on Stackoverflow
Solution 4 - asp.net MvcJoel WiklundView Answer on Stackoverflow