zoukankan      html  css  js  c++  java
  • [转载]Server.MapPath和Request.MapPath()的用法

    Server.MapPath和Request.MapPath()的用法

    转载自:https://blog.csdn.net/blocksom/article/details/7785570

     
    ./当前目录 
    /根目录 
    ../上层目录(相对当前来说) 
    如果当前的网站目录为D:\wwwroot    浏览的页面路径为D:\wwwroot\company\news\show.asp 
    在show.asp页面中使用
    Server.MapPath("./")   返回路径为:D:\wwwroot\company\news 
    Server.MapPath("/")    返回路径为:D:\wwwroot 
    Server.MapPath("../")   返回路径为:D:\wwwroot\company 
    server.MapPath(request.ServerVariables("Path_Info")) 
    Request.ServerVariables("Path_Translated")   
    上面两种方式返回路径为 D:\wwwroot\company\news\show.asp 


    ASP.NET中Server.MapPath() 和 Request.MapPath()区别: 
    Server.MapPath(string)   :是将相对于当前调用文件的文件(或目录)映射为物理路径; 
    Request.MapPath(string) :是将string虚拟路径映射为物理路径(asp中Request无此方法) 
    Server.MapPath(string) 中string 可以用“../”方式引用父目录,甚至可以将此目录跳到整个WEB目录外,如:C:\WWWROOT 
    目录为WEB根目录,在根目录文件中调用此Server.MapPath("../xyz.gif"),则可以调用WEB目录外的脚本、资源等。 
    Request.MapPath(string) 中的string为虚拟目录,只能相对WEB虚拟目录形式的,也不允许"../"方式调用,只能是"/","/xx"等字符串 
    有时候直接用Server.MapPath(string) 调用一个文件比较麻烦,因为不同的目录中调用同一个Server.MapPath(string) 函数就会得到不同的值, 
    特殊的话,就需要通过判断本身目录层次才能获取正确的地址,使用的Request.MapPath(string)就可以调用同一个目录文件。不用做目录判断
  • 相关阅读:
    [SCOI2007]降雨量
    [SCOI2005]骑士精神
    LUOGU P1342 请柬
    spfa的复活
    Luogu P2396 yyy loves Maths VII
    Luogu P2801 教主的魔法
    HEOI2012 采花
    USACO05DEC Cleaning Shifts
    CF438D The Child and Sequence
    Codechef October Challenge 2019 Div.2
  • 原文地址:https://www.cnblogs.com/hx215267863/p/12048880.html
Copyright © 2011-2022 走看看