KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I get an incorrect URL from the Action method when I use a URL rewrite. I have this rewrite rule in web.config: <rule name="Old Objects 2" stopProcessing="true"> <match url="^transportbilar/(nya|begagnade|miljobilar)/(.*)$" ignoreCase="true"/> <action type="Rewrite" url="/transportbilar/{R:2}"/> </rule> This will rewrite an URL like /transportbilar/nya/fiat/7s76s8dg to /transportbilar/fiat/7s76s8dg , which works fine, but the Url.Action gets confused by this. I use an expression like this to create an URL in the page: url.Action("Slideshow", "Object", new { id = objectId }); When the URL rewrite is not used (browsing directly to the page), this produces the correct URL /Object/Slideshow/7s76s8dg , but when the URL rewrite is used, the Action method adds the first part of the page URL to the generated URL, and produces the incorrect URL /transportbilar/Object/Slideshow/7s76s8dg . I think that I can do a Redirect in the rewrite rule instead, which would circumvent the problem as the requesting URL would change, but is there a way to make it work without changing it to a Redirect? Edit: The routes that I think could possibly be relevant are these (added in this order): transportbilar/handlare/{id}/{criteria} transportbilar/handlare transportbilar transportbilar/sokresultat/{criteria} transportbilar/{brand}/{id}/{criteria} {controller}/{action}/{id} The last route would catch the url /Object/Slideshow/7s76s8dg and the second from last would catch /transportbilar/fiat/7s76s8dg .
Tags (comma-separated)
Save Edits
Cancel