1

i need to implement asp.net url rewriting using regular expression in global.asax in one line for this solution

www.dummydomain.com/a/1/b/2/c/3/d/4/...                    
www.dummydomain.com/b/2/c/3
www.dummydomain.com/b/2/a/1/c/3/

it means changing the parameter sequence should not affect + number of distinct params will be dynamic + i can access these parameters value by name e.g. a, b, c

2
  • This is a very bad idea, because it means, that possibly two or more urls can point to a single page. Epic SEO suicide, not mentioning technical problems you're facing while implementing this scenario. What I'd suggest is to use different means of passing variables - session, cookies, hidden fields, viewstate... Especially when you need to juggle with variables like this. Commented Oct 7, 2012 at 11:54
  • I know what you're saying. i just wanted to know if it is possible using url-rewriting+regular-expression not by parsing the url as the guy below said. i havn't got time to do it myself but i am sure it would be possible Commented Oct 7, 2012 at 19:12

2 Answers 2

1

You can configure URL rewriting rules via web.config and also programatically.

Look at following MSDN article, it explains it in depth

http://msdn.microsoft.com/en-us/library/ms972974.aspx

Also in short words to rewrite URLs programarically call HttpContext.RewritePath(string path) from Application_BeginRequest() in global.asax.cs

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the split option for strings and then put your values into a dictionary. This assumes that your pattern will never break.

Dim MyContext = HttpContext.Current
Dim url = Request.Path.ToLower()
url = url.Trim("/")
Dim Vals = url.Split("/")
Dim Dict As New Dictionary(Of String, String)
for i = 0 to (vals.count/2)-1
     Dict.Add(vals(i),vals(i+1))
next

You can then use the dictionary object to locate your variables.

Run this in your global.asax file in the Application_BeginRequest method and call MyContext.RewritePath to send the user to the correct path.

if dict("a") = 1 then MyContext.RewritePath("new URL")

2 Comments

You seriously encourage him to do this? :) Either way, you've shown something completely different than he's actually requested. He wants to specify a route in global.asax for url routing, using a single line of code, not how you parse a url string...Moreover, when we use url routing, we refer to url variables like this: RouteData.Values["nameOfVarSpecifiedInTheRoute"], not by parsing the url itself. Don't see a reason for parsing it like this, when we already have means for retrieving values of url variables...
He can use those parameters to figure out his route. I'm answering the guys' question even if it's weird. And for your reference you can run this in your global.asax file in the Application_BeginRequest method and call MyContext.RewritePath to send the user to the correct path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.