1

I am working with URL routing , and have some issues. I want my url to be like this:

www.domain.com/p/myproduct

But I also want to be able to retrieve the ID of the product, without accessing the database. I thought about having a URL like:

www.domain.com/p/myproduct/1

But if I could hide the ID it would be better.

So, how do I do it the simplest way?

Currently my Global.asax has the following route:

 routes.MapLocalizedRoute("Product",
                        "p/{productId}/{SeName}",
                        new { controller = "Catalog", action = "Product", SeName = UrlParameter.Optional },
                        new { productId = @"\d+" },
                        new[] { "Nop.Web.Controllers" });
Sushant Bhatnagar
  • 3,684
  • 10
  • 31
  • 42
  • If your problem is related to how to route data, [read this](http://stackoverflow.com/questions/7851730/mvc-route-actionlink-url-use-name-instead-of-id). However, retrieving the ID of a product from a url like `www.domain.com/p/myproduct` will prove difficult. The only way I can think of is hiding the ID in a POST request, but that would be a really bad idea. – kdrvn Oct 25 '12 at 11:14
  • possible duplicate of [ASP.NET MVC - hiding id in URL?](http://stackoverflow.com/questions/2952367/asp-net-mvc-hiding-id-in-url) – Brian Diggs Oct 25 '12 at 22:02

1 Answers1

0

If all you have is the url then you will have to include the ID there if you want to read it.

The only way to hide it is if you have the ID coming to you from the post of a form say, assuming they have come from a previous page. Then you could store the selected Id and post to url as part of the request.

dove
  • 20,469
  • 14
  • 82
  • 108