Can i rewrite URL in MSVS?
-
05-07-2019 - |
Question
I am using MSVS 2008, C#, ASP.NET project. Right now i can serve any pages i want under http://localhost:3288/ExistingPageInProject.aspx
In MSVS how do i map http://localhost:3288/u/SOME_USER_NAME/media/TITLE-0123 to point to a file/page i have. Such as /u/ExamplePage?name=SOME_USER_NAME&title=TITLE-0123
NOTE: 0123 is the mediaId so the title can be ignored.
Solution
The way I personally do it is to use Application_BeginRequest in public class Global : System.Web.HttpApplication and parse the URL with Regex or whatever, and then use HttpContext.Current.RewritePath to serve the correct page without doing a redirect.
There are also other ways to do it, but that's my preference and its easy to implement.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow