|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Regular Expression Help (URL Rewriting)make it more dynamic. I am doing this via Global.asax and as of now I have to manually write the URL's one-by-one. I am wanting to use a RegEx on a string and then access the dynamic page this way. For example: Let's say that the static URL I implement is: Wonkas_widgets_factory_Tonka_Truck_002.aspx I would want this to point to: product.aspx?productID=002 To accomplish this I would simply need to use the RegEx: \d{3} Now let's say that I have the following code in Application_BeginReguest (Global.asax): Sub Application_BeginRequest(ByVal sender as Object, ByVal e as EventArgs) Dim httpContext As System.Web.HttpContext = httpContext.Current Dim currentURL As String = Request.Path.ToLower() If currentURL.IndexOf("Willy_Wonkas_widget_factory_001") > 0 Then httpContext.RewritePath("product.aspx?productID=001") End Sub What would be the best way to implement this RegEx so that I can create many static URL's? *** Sent via Developersdex http://www.developersdex.com *** I'm sure I can help with regular expressions, but I don't understand
what you're asking. Sorry,
I couldn't figured this out earlier. I should've posted a reply to myself. Sub Application_BeginRequest(ByVal sender as Object, ByVal e as EventArgs) Dim httpContext As System.Web.HttpContext = httpContext.Current Dim currentURL As String = Request.Path.ToLower() Dim strPattern As String = "page(\d+).aspx" Dim objRegEx As Regex Dim Matches As MatchCollection Dim pageID As string objRegEx = New Regex(strPattern, RegexOptions.IgnorePatternWhitespace) Matches = objRegEx.Matches(currentURL) If Matches.Count > 0 Then pageID = Matches(0).Groups(1).ToString() httpContext.RewritePath("product.aspx?productID=" & pageID) Else httpContext.RewritePath(currentURL) End If *** Sent via Developersdex http://www.developersdex.com ***
Other interesting topics
Deploying ASP.NET 2.0
Web Development articles - where can I find some? how to parse deeper nested tags in custom control ## in ASP.NET 2.0 Don't Understand error DataGrid Pagin Problem How and when should I use CacheItemPriority.NotRemovable? Multilanguage calendar... control events Strange Behavior ASPnet_Wp.exe |
|||||||||||||||||||||||