文章类型: .NET
关键词: 如何,用,c#,js,javascript,获得,当前站点,根路径
内容摘要:

如何用c#和js获得当前站点的根路径

2015/7/29 14:12:18    来源:apple    阅读:

使用C#来实现:

public static string GetRootPath()
{
    // 是否为SSL认证站点
    string secure = HttpContext.Current.Request.ServerVariables["HTTPS"];
    string httpProtocol = (secure == "on" ? "https://" : "http://");
    // 服务器名称
    string serverName = HttpContext.Current.Request.ServerVariables["Server_Name"];
    string port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
    // 应用服务名称
    string applicationName = HttpContext.Current.Request.ApplicationPath;
    return httpProtocol + serverName + (port.Length > 0 ? ":" + port : string.Empty) + applicationName;
}

使用js来实现:

//js获取项目根路径http://localhost:1396/Web
function getRootPath() {
    return window.location.protocol+"//"+window.location.host;
}

 

↑ 上一篇文章:asp.net中Response.Redirect与Server.Transfer的区别分析 关键词:asp.net,Response,Redirect,Se.. 发布日期:2015/7/29 14:11:27
↓ 下一篇文章:Java基础知识 关键词:S1,Java,基础,知识,问答题 发布日期:2015/7/29 14:13:22
相关文章:
JS与C#的函数以及变量互调 关键词:JS,javascript,C#,函数,变量,互调,调用 发布日期:2015-07-29 14:08
C# 弹出消息框后跳转另一页面 关键词:C#,弹出,消息框,跳转,另一页面,Response,Write,js,javascript,C.. 发布日期:2015-07-29 14:42
JavaScript 和 .NET 中的 JSON 关键词:js,JavaScript,.net,C#,json 发布日期:2015-07-14 17:26
相关目录:.NET软件开发JAVASCRIPTANDROID
我要评论
正在加载评论信息......