获取根目录的URL的方法(asp.net)

每天积累一点点,

一、获取获取根目录的URL的方法

#region 获取本页根目录URL
public static string GetRootURI()

{
    string AppPath = "";
    HttpContext HttpCurrent
= HttpContext.Current;
    HttpRequest Req;
    if
(HttpCurrent != null)
    {
        Req =
HttpCurrent.Request;

string UrlAuthority =
Req.Url.GetLeftPart(UriPartial.Authority);
    if
(Req.ApplicationPath == null || Req.ApplicationPath == "/")
   
    //直接安装在 Web 站点
        AppPath =
UrlAuthority;
    else
        //安装在虚拟子目录下

    AppPath = UrlAuthority + Req.ApplicationPath;
   
}
    return AppPath;
}
#endregion

二、获取全URL

IN_URL = Request.Url.ToString();

希望积少成多,水滴石穿!

获取根目录的URL的方法(asp.net)

时间: 2024-08-11 13:04:50

获取根目录的URL的方法(asp.net)的相关文章

js获取当前页面的url信息方法

例如网址:http://localhost:12085/My/OrderM.aspx 设置或获取对象指定的文件名或路径. alert(window.location.pathname) 输出结果:/My/OrderM.aspx 设置或获取整个 URL 为字符串. alert(window.location.href); 输出结果:http://localhost:12085/My/OrderM.aspx 设置或获取与 URL 关联的端口号码. alert(window.location.port

ASP.NET获取请求的url信息汇总

ASP.NET获取请求的url信息汇总 最近做项目需要处理一个用代码获取当前网站的域名或ip信息的问题,于是尝试了ASP.NET中各种获取url信息的方法,在此总结一下: 在Global.asax文件中的 Application_BeginRequest 方法中,加入以下代码,利用日志文件记录各种方法得到的信息 HttpApplication app = sender as HttpApplication; logger.Debug("Request.ApplicationPath:"

Web应用中request获取各种获取path或URI,URL的方法

Web应用中有各种获取path或URI,URL的方法,假设网页访问地址: http://localhost:8080/tradeload/TestServlet Web应用context: /tradeload 各路径鉴定如下: request.getContextPath()= /tradeload request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort

JavaScript获取后台C#变量以及调用后台方法 && 获取请求的URL参数

一.当然我们可以在后台中获取参数的值,然后在前台js代码中获取变量的值,具体做法请参考下面JavaScript获取后台C#变量以及调用后台方法. 其实我们也可以直接在js中获取请求的参数的值,通过使用window.location.search可以获取到当前URL的?号开始的字符串,如前面的链接获取到的search为?id=001.再对获取的字符串进行处理,就可以获取到参数的值了. 复制代码 代码如下: 1 function getUrlParam(name) { 2 var reg = new

ASP.NET获取IP的6种方法(转载于LanceZhang's Tech Blog)

服务端: 1 //方法一 2 HttpContext.Current.Request.UserHostAddress; 3 4 //方法二 5 HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; 6 7 //方法三 8 string strHostName = System.Net.Dns.GetHostName(); 9 string clientIPAddress = System.Net.Dns.GetHostA

iframe笔记及获取根目录的方法

iframe外面的js不能调用里面的dom,只能通过调用里面的js方法来调用. iframe外面的js调用里面的js方法:通过iframe的name.里面的js方法名调用. 初始化外面的jq: $(function(){ outiframe.init(); ); outiframe = { init : function(){ //方法内容,如调用iframe里面的方法 iframe的nane.ineriframe.inermethod1(); }, method : function(){ /

【ASP.NET】ASP.NET获取IP地址的六种方法

服务端: //方法一 HttpContext.Current.Request.UserHostAddress;  //方法二 HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; //方法三 string strHostName = System.Net.Dns.GetHostName(); string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostN

用js获取当前页面的url的相关信息方法

1. 当前页面的完整url获取方式: window.localtion.url; 2. pathname部分: window.location.pathname 3. 设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或获取与 URL 关联的端口号码. alert(window.location.port) 设置或获取 URL 的协议部分. aler

如何用js得到当前页面的url信息方法(JS获取当前网址信息)

设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或获取与 URL 关联的端口号码. alert(window.location.port) 设置或获取 URL 的协议部分. alert(window.location.protocol) 设置或获取 href 属性中在井号“#”后面的分段. alert(window.location.hash) 设