Last post Jul 17, 2007 07:27 AM by AndrewSeven
Jul 16, 2007 05:41 AM|kmcnet|LINK
Hello Everyone and thanks for your help in advance. I am new to URL Remapping and am trying to work through my first project. Basically, I have a one page website where the default page is dynamically changed when various parameters in the querystring
are passed. The defaul page is in the root directory and appropraitely named Default.aspx. I woulld like to create links that would be formatted something like /articles/1/aspx or resume/1.aspx with the idea that articles or resume would determine the category
to be loaded and the 1 in the link would be the item in that subcategory. To that end I have written the code below:
Dim URLMatch As String = "Resume/.*"
Dim URLMatch2 As String = "Articles/.*"
' Fires at the beginning of each request
Dim URLRequest As HttpContext = HttpContext.Current
Dim NewURL As String = ""
Dim RequestedURL As String = URLRequest.Request.Path.ToLower
RequestedURL = URLRequest.Request.AppRelativeCurrentExecutionFilePath
If Regex.Match(RequestedURL, URLMatch).Success Then
'Response.Write("Found " & CheckURL)
NewURL = "/Default.aspx?CP=Resume"
ElseIf Regex.Match(RequestedURL, URLMatch2).Success Then
NewURL = "/Default.aspx?CP=Articles"
On the default page, I have added the two links:
NavigateUrl="Articles/2.aspx">Click Here For Articles</asp:HyperLink>
Here is my probem. For example, when I click on the link Articles for the first time, the address bar shows /Articles/1.aspx. Then, if I click on the Resume link, the address bar shows /Resume/Article/1.aspx. Then, each
subsequent link click takes the address bar further down the hierarchy. Additionally, since I am parsing for either resume or article, the parsing stops working correctly after the first click. Obviously I haven't even begun to work on parsing out the "1"
or "2" item numbers in the string. I guess I have two questions. First, how do i go aobut fixing this problem. Second, is the whole concept of using one page and dynamically changing it like the a poor choice. Any help would be greatly appreciated. Thanks.
Jul 16, 2007 09:25 AM|AndrewSeven|LINK
Your current issue might just be the NavigateUrl="Resume/1.aspx" needing to be
I have an example using an http hanlder factory to do the equivalent of url rewriting.
Jul 16, 2007 08:37 PM|kmcnet|LINK
First of all, thanks for the assistance. I greatly appreciate it. I took a look at your code and the one question I have is why use IHttpHandlerFactory at all since there appears to be simpler ways to reach the same result. I'm sure there is a pretty
good reason, but since I'm not really up to speed on this topic, the nuances are lost on me. Can you please run me through this a little deeper?
Once again, thanks for the assistance.
Jul 17, 2007 07:27 AM|AndrewSeven|LINK
Over time, I've tried a couple different approaches and the factory has been the most dependable (least leaky).
When a page is requested, the handler factory serves it as though it actualy existed at that location.
My sample may seem more complicated than it is because of the way things are abstracted.