kob*_*obe 26
string url = HttpContext.Current.Request.Url.AbsoluteUri;
Run Code Online (Sandbox Code Playgroud)
http://thehost.com/dir/Default.aspx
string path = HttpContext.Current.Request.Url.AbsolutePath;
Run Code Online (Sandbox Code Playgroud)
/dir/Default.aspx
string host = HttpContext.Current.Request.Url.Host;
Run Code Online (Sandbox Code Playgroud)
thehost.com
从代码隐藏文件获取URL的另一种方法
public string FullyQualifiedApplicationPath
{
get
{
//Return variable declaration
var appPath = string.Empty;
//Getting the current context of HTTP request
var context = HttpContext.Current;
//Checking the current context content
if (context != null)
{
//Formatting the fully qualified website url/name
appPath = string.Format("{0}://{1}{2}{3}",
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port == 80
? string.Empty
: ":" + context.Request.Url.Port,
context.Request.ApplicationPath);
}
if (!appPath.EndsWith("/"))
appPath += "/";
return appPath;
}
}
Run Code Online (Sandbox Code Playgroud)
检查此链接,您将获得更多信息.
| 归档时间: |
|
| 查看次数: |
63785 次 |
| 最近记录: |