You are here:   Home
Register   |  Login

Captured Technology - Blog

Minimize

Getting the Current URL in Asp.Net

Nov 5

Written by:
11/5/2009 4:18 PM  RssIcon

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

Tags:
Categories:

7 comment(s) so far...


Gravatar

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
Gravatar

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
Gravatar

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
Gravatar

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
Gravatar

Re: Getting the Current URL in Asp.Net

Thanks for this code :)

By Mia on   12/6/2009 6:42 PM
Gravatar

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
Gravatar

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

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

FaceBook

Minimize

Mobile Version

Minimize
Add CapturedTech - Technology Mippin widget

Translate

Minimize

Sponsors

Minimize
Enroll in home water delivery today!

Recent Comments

Minimize
Re: Three Benefits to Using a Royalty-Free Image on Your Website or Blog
Don't pay for royalty free images. They are free after all! I offer links to 96 websites that have tens of thousands (maybe even hundreds of thousands) of absolutely free images, including ones for commercial use! All you need to do is subscribe to my blog at www.davesinternetmarketing.info/royalty-free-images-free-for-commercial-use/
Re: Buzzom Offers Featured User Options
This is when discovered this great new way to grow your follow list. You can pay between $10 and $100 for the number of times you want to app ar at the top of the list.
Re: Microsoft Test Bounties
I had spent a good deal of my time looking for someone to explain this subject clearly and I have really enjoyed reading your blog posts and I collected a lot of interesting things as well as I done a research on the subject and learn most peoples will agree with your blog.
Re: 10 Ways to Source Great Sales Leads
Hoovers.com, that have contact information for tens of millions of businesses. If necessary, you can work with these companies' research teams to order lists specifically tailored to your organization's sales needs.
Re: Microsoft Test Bounties
To find bugs and showing it to microsoft is quite admirable. Keep blogging more i will appreciate.

u comment, i follow