设计图

asp.net服务器信息获取_asp.net


 

代码

protected void Page_Load(object sender, EventArgs e)

    {

        string a, b;

        a = Session["user"] + "";


        b = Session["password"] + "";

        if(!((a=="张三")&&(b=="123")))

        Response.Redirect("login.aspx");

        Response.Write("获取客户信息:");

        Response.Write("<br><hr>");

        Response.Write("客户端IP地址:");

        Response.Write(Request.UserHostAddress);

        Response.Write("<br>当前应用程序根目录的实际路径:");

        Response.Write(Request.PhysicalApplicationPath);

        Response.Write("<br>当前页面所在的虚拟目录及文件名称:");

        Response.Write(Request.CurrentExecutionFilePath);

        Response.Write("<br>当前页面所在的实际目录及文件名称:");

        Response.Write(Request.PhysicalPath);

        Response.Write("<br>当前页面URL:");

        Response.Write(Request.Url);

        Response.Write("<hr>");

        Response.Write("获取服务器端环境变量<br><hr>");

        Response.Write("<table border=1>");

        Response.Write("<tr bgcolor=blue>");

        Response.Write("<td>环境变量</td>");

        Response.Write("<td>当前值</td>");

        Response.Write("</tr>");

        foreach(object item in Request.ServerVariables)

        {

            Response.Write("<tr>");

            Response.Write("<td>"+item+"</td>");

            //显示变量

            Response.Write("<td>"+Request.ServerVariables[item.ToString()]+"</td>");

            //获取服务器变量,并将变量值转换成字符串

            Response.Write("</tr>");

        }

        Response.Write("</table>");

    }

效果:

 

asp.net服务器信息获取_asp.net_02