usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Net;usingSystem.Text;usingSystem.Web;namespaceSurinderBhomra.Common.Extensions{publicstaticclassUrlExtensions{/// <summary>/// Checks if the link is an internal or external link./// </summary>/// <param name="link"></param>/// <returns></returns>publicstaticboolIsExternalLink(thisstringlink){returnlink!=string.Empty&&link.ToLower().StartsWith("http://")||link.ToLower().StartsWith("https://");}/// <summary>/// Get domain from current http context./// </summary>/// <param name="context"></param>/// <returns></returns>publicstaticstringGetCurrentDomain(thisHttpContextcontext){context=HttpContext.Current.GetOrCreateNewInstance();if(context!=null)return$"{HttpContext.Current.Request.Url.Scheme}{Uri.SchemeDelimiter}{HttpContext.Current.Request.Url.Host}{(!HttpContext.Current.Request.Url.IsDefaultPort ? $":{HttpContext.Current.Request.Url.Port}" : null)}";returnstring.Empty;}}}
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.