-1

假设我们在页面上www.abc.com/apple-store

那么如何apple-store在asp C#代码中获取字符串。

存储到另一个变量中。

4

3 回答 3

1

您应该使用该Request.RawUrl属性。在此处查看更多详细信息。

或者,您也可以使用Request.Url(参见此处)属性来获取当前 URL 的不同部分。例如,您将使用Request.Url.LocalPath.

于 2014-11-07T08:57:50.750 回答
1

您可以使用 string.last() 来提取它。

string lastPartUrl =HttpContext.Current.Request.Url.AbsoluteUri.Split('/').Last();
于 2014-11-07T09:10:24.497 回答
0

您可以在字符串变量中获取 url。此外,您可以实现以下逻辑,将值保存在变量中。

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);`

希望这个对你有帮助。

于 2014-11-07T10:03:27.397 回答