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 }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步