【发布时间】:2016-09-12 06:32:04
【问题描述】:
我想为自己上课,我正在编写这段代码,但我碰壁了
public static string url(string example)
{
string back = "";
if(example == "random1")
{
back = "Request.Url.AbsolutePath.ToString()";
}
return back;
}
我想在我的 asp 网络项目示例中使用我的 Request.Url.AbsolutePath.ToString() 命令 > default.aspx.cs > url("random1");
我已经搜索了很长时间,抱歉英语低:/
【问题讨论】:
-
只需要去掉 Request.Url.Absolute.ToString() 周围的双引号
-
img这个问题
-
您有 System.Web 的 using 语句吗?如果您在上课,您可能必须使用完整路径:System.Web.HttpContext.Current.Request.Url.AbsolutePath.ToString()
-
谢谢它正在工作,我可以将此方法用于其他 C# 命令吗?
-
是的,在需要时。您只需在 using 语句中包含要使用的库,在本例中为 System.Web。
标签: c# asp.net variables dynamic command