Suppose We are on the page www.abc.com/apple-store
then how to get string apple-store
in asp C# code.
to store into another variable.
Suppose We are on the page www.abc.com/apple-store
then how to get string apple-store
in asp C# code.
to store into another variable.
You should use the Request.RawUrl
property. See more details here.
Alternatelly you can also use the Request.Url
(see here) property to get different parts of the current URL. For example you will get the same result using Request.Url.LocalPath
.
You can use string.last() to extract it.
string lastPartUrl =HttpContext.Current.Request.Url.AbsoluteUri.Split('/').Last();
You can get the url in a string variable. Further you can implement the below logic which will save the value in a variable.
string str = "www.abc.com/apple-store";
string result = "";
int i= 0;
int len = str.Length;
//Get the index of the character
i = str.IndexOf('/');
//store the result in the variable
result = str.Substring(i+1,len-i-1);
Console.WriteLine("Resultant:- {0}", result);`
Hope this helps a bit.