C#获取当前站点的根地址

 1         /// <summary>
 2         /// 得到当前网站的根地址
 3         /// </summary>
 4         /// <returns></returns>
 5         protected string GetRootPath()
 6         {
 7             // 是否为SSL认证站点
 8             string secure = HttpContext.Current.Request.ServerVariables["HTTPS"];
 9             string httpProtocol = (secure == "on" ? "https://" : "http://");
10             // 服务器名称
11             string serverName = HttpContext.Current.Request.ServerVariables["Server_Name"];
12             string port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
13             // 应用服务名称
14             string applicationName = HttpContext.Current.Request.ApplicationPath;
15             return httpProtocol + serverName + (port.Length > 0 ? ":" + port : string.Empty) + applicationName;
16         }

C#获取当前站点的根地址

时间: 2024-08-01 12:41:34

C#获取当前站点的根地址的相关文章

php获取站点的根目录和站点的根URL

如果网站不是在服务器的根目录下,可以这样做: $url = str_replace('\\','/',realpath(dirname(__FILE__). '/../') . '/'); define('ROOT',$url);//这里的ROOT是网站的根目录 $htp = $_SERVER['HTTP_HOST'];//获取当前的服务器名 $root = $_SERVER['DOCUMENT_ROOT'];//获取服务器的根目录 $dir = str_replace($root , "htt

request.getContextPath是为了解决相对路径的问题,可返回站点的根路径

假定你的web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果: 1. System.out.println(request.getContextPath()); 打印结果:/news   2.System.out.println(request.getServletPath()); 打印结果:/main/list.jsp3. System.out.print

如何获取陌生服务器的IP地址

如何获取陌生服务器的IP地址 一.背景 在机房里有一台生产系统的服务器,该服务器有带外管理卡,但是管理卡的IP地址被其他同事修改过,现在已经不能找到历史记录,如果要实现这台服务器的带外管理功能,就必须知道服务器的带外管理卡IP地址,怎么解决呢? 二.解决办法 1.可以对这台服务器进行重启操作,然后登陆设备后台进行查找或修改,这种方式目前不可行. 2.可以通过抓包的方式实现,用一台笔记本随便配置一个IP地址如172.16.1.1,然后通过网线与这台服务器的带完管理卡直连,启用抓包软件进行转包. (

Atitit.获取approot&#160;api&#160;应用根路径&#160;java&#160;c#.net&#160;php&#160;asp

Atitit.获取approot api 应用根路径 java c#.net php asp 1. 如果根路径返回empty,否则返回/app,兼容getContextPath() <script type="text/javascript" src="../com.attilax/core/approot_js.jsp"></script> <%@ page contentType="text/html; charset=u

黄聪:WordPress 多站点建站教程(六):使用WP_Query、switch_to_blog函数实现获取子站点分类中的文章

首先在你使用主题的funtions.php里面添加下代码: //根据时间显示最新的分类文章内容,每个站点显示一篇内容 //$blog_id 子站点ID //$catid 分类ID wp_reset_query(); switch_to_blog($blog_id); global $post;?> $my_query2 = new WP_Query('showposts=1&order=desc&orderby=date&cat='.$catid); while ($my_q

用Linux命令行获取本机外网IP地址

用Linux命令行获取本机外网IP地址 $ curl ifconfig.me$ curl icanhazip.com$ curl ident.me$ curl ipecho.net/plain$ curl whatismyip.akamai.com$ curl tnx.nl/ip$ curl myip.dnsomatic.com$ curl ip.appspot.com$ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\)

Onvif 获取指定通道的流媒体地址

GetStreamUri函数可以获取流媒体地址.代码如下:void UserGetUri(const char* xAddr){ int result=0 ; struct soap *soap = soap_new(); struct _trt__GetStreamUri trt__GetStreamUri ; struct _trt__GetStreamUriResponse trt__GetStreamUriResponse; printf("\n\n---------------Gett

python之获取微信服务器的ip地址

# -*- coding: cp936 -*- #PYTHON 27 #xiaodeng #获取微信服务器的ip地址 import urllib url='https://api.weixin.qq.com/cgi-bin/getcallbackip' data={'access_token':'VchuOKNr8X9tZVDrY_yG9qiJus_1nO1a7uT_iwWVwgGFdzPhPyaqreTE_qMKPas4SwRNif5k0A1zVw6Y9eTPI4CAYiUwpJvHdBt4f

PHP获取用户的真实IP地址

本文出至:新太潮流网络博客 PHP获取用户的真实IP地址,非代理IP function getClientIP(){ global $ip; if(getenv("HTTP_CLIENT_IP")){ $ip = getenv("HTTP_CLIENT_IP"); }else if(getenv("HTTP_X_FORWARDED_FOR")){ $ip = getenv("HTTP_X_FORWARDED_FOR"); }e