Url based aide methods including:


Returns a string containing the scheme, host and port for the current HttpContext e.g. http://www.mysite.com:8080

{String GetSchemeHostAndPort(HttpContext context)}


As above, put appends a forward slash e.g. http://www.mysite.com:8080


Resolves a url to include the full application path e.g. ~/news/index.htm coule resolve to /mywebsite/news.index.htm

{String Resolve(String value)}


This is useful for generating friendly urls from such items as products, news stories etc stored in a database.

Takes a string, removes non alphanumeric characters, converts spaces to "-" and lowercases.

e.g. "My news story" would become "my-news-story"

string url = String.Contact(UrlAide.MakeUrlSafe("My news story"), ".htm");

// url would equal "my-news-story.htm"


Given a url string, allows you to change the value of querystring parameter e.g.

string url = "test.htm?id=2&test=false";
url = UrlAide.ChangeQueryStringValueInUrl(url, id, "10");

// url would equal "test.htm?id=10&test=false";

This will add a querystring parameter if it is not already part of the passed url.

Last edited Mar 10, 2007 at 11:47 AM by stebrennan, version 3


No comments yet.