Getting the Current URL in Asp.Net
Nov
5
Written by:
11/5/2009 4:18 PM
Getting the Current URL in Asp.Net
We had the need within a custom asp.Net control this week to obtain the current URL, compare it to a value, and take action if the values matched. I found online some quick and easy code to determine the URL of the page the control is loading on and the function to take action was developed rather quickly thereafter.
Here is the basic code to get the URL:
Request.Url.ToString()
And using a combination of the Mid function and the Instr function, we are able to match values regardless of the environment the code is running in:
If Mid(strLinkURL, InStr(strLinkURL, "Pages")) = Mid(Request.Url.ToString(),
InStr(Request.Url.ToString(), "Pages")) Then
strReturn = "<b>" & strLinkText & "</b>"
Else
strReturn = "<a href='" & ResolveUrl(strLinkURL) & "' target='" & strLinkTarget & "'>"
& strLinkText & "</a>"
End If
© 2009
CapturedTech.com
7 comment(s) so far...
Re: Getting the Current URL in Asp.Net
Very helpful code when developing asp.net controls.
By Reverse Cell Phone Lookup on
11/5/2009 11:32 PM
|
Re: Getting the Current URL in Asp.Net
this is wonderful it has increased bit of more knowledge of mine.
By thinkgeek coupons on
11/8/2009 10:47 AM
|
Re: Getting the Current URL in Asp.Net
That was helpful piece of code, do you mind if i use it in my code
By coderbuddy on
11/24/2009 1:44 AM
|
Re: Getting the Current URL in Asp.Net
ASP.NET is a server side scripting language, since you have so many question marks you may want to stick with HTML. =)
By humming bird feeders on
11/24/2009 12:08 PM
|
Re: Getting the Current URL in Asp.Net
Thanks for this code :)
By Mia on
12/6/2009 6:42 PM
|
Re: Getting the Current URL in Asp.Net
There are times in your scripts when you are going to want to get the current page URL that is shown the browser URL window..really it is so simple and easy to use code.
By Venice Hotels on
8/9/2010 3:36 AM
|
Re: Getting the Current URL in Asp.Net
URL rewriting is great and the examples you provided are excellent! I found very great information in your blog Thanks for sharing his great blog with us.
By custom vinyl stickers for cars on
7/10/2011 1:04 PM
|