Try our conversational search powered by Generative AI!

Check if Url property is external or internal



I have a property of type Url, and I want to check if it is internal or external. How do I do that?

Url link = CurrentBlock.RelatedInfoLink;


Nov 18, 2014 12:23


How do you mean internal link? You mean the link used in CMS edit mode or the permanent link?


Nov 18, 2014 12:57

I'm assuming you want to check if your link points to an internal page or an external URL.

The URL property type doesn't have a method for checking that. 

I think the closest you can get is to check if link.Host matches your siteUrl.

Edited, Nov 18, 2014 14:30

I know this is old but you could use @Url.IsLocalUrl(link.Href) to check if a link is internal.

May 04, 2021 0:13
Eric - Feb 01, 2022 20:06
This is currently the best way and also a hidden gem that few know about. Thanks for the answer!! :)
Always been a bit of a problem to determine the best way to check if a link is external or not.
Ethan Schofer - Jan 03, 2024 21:23
Nice. Thanks Santiago!!!
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.