Showing posts with label URL. Show all posts
Showing posts with label URL. Show all posts

Friday, July 25, 2014

Getting the left section of current Url upto domain name in C#

I was creating product's full links dynamically to do this I need to have the left section of the current URL from http to end of domain name.

Example:

My full link:
http://pro-post.blogspot.in/2014/07/extended-dropdownlistfor-to-create.html

I need: 
http://pro-post.blogspot.in

To achieve this ->

string leftSection = System.Web.HttpContext.Current.Request.Url.OriginalString.Replace(
System.Web.HttpContext.Current.Request.Url.PathAndQuery, "")
leftSection = leftSection.Substring(0, leftSection.LastIndexOf(':'));

ref: Soumyadip [http://soumyadip-cooldips.blogspot.in]