1

I would like to make my app url like http://domain.com/product/product-name....

Is it possible that is if I am passing productid and can get productname in my url?

1
  • I dont want to down vote this, but this is a very common procedure in asp mvc and the is more then enough documentation on the net on this. Commented Apr 3, 2015 at 11:40

1 Answer 1

1

URL Rewriting is the practice of "faking" a URL by rewriting it to look like another URL. It does so in a single direction. This means it is has no built-in way to generate a URL for use on the UI.

.NET Routing is what MVC applications typically use. It is a real, not faked 2-way mapping from URL to a set of route values and/or a set of route values to a URL. This means that you can easily generate URLs for use within the application using HTML helpers such as ActionLink, and as such is the recommended and preferred approach for building custom URLs from within the application.

Sometimes both of these techniques are used, but URL rewriting is generally only put in place to do things that make sense to change from outside of the compiled application, such as when nesting the application within another application or putting in one-way 301 redirects for legacy URLs.

To answer your question, yes it can be done, but should be done with .NET routing, not URL rewriting. To use names like this, you need a mapping between name and ID. A couple of ways this could be done:

  1. Make a Name-ID mapping right in your route configuration by using static route segments with the name and route values that contain the related ID. This approach will work only if your URLs don't need to be changed dynamically within the application.
  2. Use a Name-ID map within a cached dictionary object. Use a custom RouteBase implementation to do mapping in each direction by overriding the GetRouteData and GetVirtualPath methods.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.