ASP.Net MVC Routing - using same pattern for different controllers -
I have an ASP.NET MVC site with products and categories, and I need this URL ...
Products:
- Forstop
- Foolspeka / Squische-Orange
- Foolsps / Chrome -steppe-apple
- FaceSpek / MegaOrange / Ul>
- Forstspadpad
-
There is a pattern or regular expression (which I can see, anyway), which allows me to determine the URL by viewing, if it is a product or category. I need to look into the database to find out.
What would be a good way to get in touch with this?
- Register the route of each product and category at the application startup
- Make some code that handles requests, and see Slug in the database < Li> ??
Categories:
Do not think of caching, refreshing routing-tables etc. for now :)
Feel free to edit the title of my question, if you think That's a more appropriate headline for this question - it was the best I could come up with.
I prefer your view # 2 more than # 1. I think you can make a single The route goes away with a slug controller (or whatever you want to call these) in a slugger action. You only need one route for this.
Your Slalghander action will then accept a slug string, then call on a method to determine whether the Slag category or product is. (You said that these were unique, yes? I.e., there should not be a uniform slag for both the product and the category.) From there, you can call the appropriate product or category method, which passes through the slug string .
Follow some code pieces:
internal enum slugType {category, product} Define private slug type SullugTypeFromSlugName (string slug) {// some database magic here useful SlugType to back} Public ActionResult SlugHandler (String Slug) {Slug Type Slug Type = Determine SullugTypeFromSlugName (slug); Switch (slug type) {case slug type. Category: Returns category (Slug); Case slug type Products: Return Products (Slug); Default: Return SomeErrorAction (); }} Good luck!
-Mike
Comments
Post a Comment