Captured Technology

Getting the Current URL in Asp.Net

Nov 05 2009

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 = "" & strLinkText & ""
Else
       strReturn = "" 
& strLinkText & ""
End If
© 2009 CapturedTech.com

Blog Directory

Latest technology news.
 Steve Patterson
 410  245411  4/5/2017

FaceBook

Translate

Sponsors





Blog Calendar

Categories