The fifth day of the Net foundation of the Wisdom Podcast Learning

Source: Internet
Author: User

Virtual path

Special Path Identification " ~ "

And "/represents the site root directory (domain name) 、.. /indicates the parent directory,./indicates the current "HTTP standard positioning is not the same, ~ is the special symbol of the ASP. ASP, which is defined as the recommended usage, and the recommended resource location is defined using the ~ from the application root directory. The difference between applying the root directory and the Web site root is that if you deploy an app to the Http://www.rupeng.com/search directory, the root of the app is "Http://www.rupeng.com/search" and the root of the Web site is " http://www.rupeng.com/"(create website to demonstrate, because the different website are in the same site root), so it is best to use" ~ "," ~ "will not be recognized by the browser, Because some ASP. NET will convert this path to a full path relative to the root directory of the Web site and then output to the browser.

For example, use ~, rather than/the benefits. WebSite. Programmatic processing "~"

ASPX page:

   <formID= "Form1"runat= "Server">    <Div>            <ahref= "/1 virtual path. htm">A</a>    <Asp:hyperlinkID= "HyperLink1"runat= "Server"NAVIGATEURL= "./1 virtual path. htm"Text= "Cel1">HyperLink</Asp:hyperlink>    <Asp:hyperlinkID= "HyperLink2"runat= "Server"NAVIGATEURL= "~/1 virtual path/1 virtual path. htm"Text= "Cel2">HyperLink</Asp:hyperlink>    </Div>    </form>

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial class_1 Virtual Path _ path 1:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {        //Response.Write ("<a href=" +virtualpathutility.toabsolute ("~/b/c.htm") + "' > Dynamic </a>"); //Response.Write (Virtualpathutility.combine ("~/a/b", "c.htm"));Response.Write (Virtualpathutility.combine (Virtualpathutility.appendtrailingslash ("~/a/b"),"c.htm")); }}

If the "~" is automatically converted in the server-side control (using the Runat=server control), you can use a static method in the VirtualPathUtility class to convert the virtual path, the full path, and so on, if the HTML control or the code needs to be converted. For example, Virtualpathutility.toabsolute ("~/a/b1.aspx") is to convert the virtual path to the full path relative to the application root, which is/WEBSITE4/A/B1.APSX

VirtualPathUtility class Main method: String Appendtrailingslash (String virtalpath), if the path virtualpath not last "/" is added; Tring Combine ( String basepath,string relativepath), which merges two paths, a string getdirectory (string virtualpath) that returns the directory portion of the virtual path; string Makerelative (String frompath,string topath), calculates the relative path of two virtual paths; Toabsolute, converts to an absolute path.

Request Object

1, Request.apprelativecurrentexecutionfilepath, gets the virtual path of the current execution request relative to the application root, starting with ~, such as "~/handler.ashx"

2, Request.physicalapplicationpath, get the physical path of the current application, such as D:\ my document \visual studio2008\websites\website4\

3, Request.PhysicalPath, gets the physical path of the current request, such as d:\ my document \visual Studio2008\websites\website4\handler.ashx

4, Reauest.rawurl get the original request URL, Request.url get the requested URL, the difference is related to URL rewriting problems.

Create a new ASPX page with no content on the page, and the following code is in the background:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial class_2request Object 1_default:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {Response.Write (Request.apprelativecurrentexecutionfilepath+"<br/>"); Response.Write (Request.physicalapplicationpath+"<br/>"); Response.Write (Request.PhysicalPath+"<br/>"); Response.Write (Request.url+"<br/>");    Response.Write (Request.rawurl); }}

The fifth day of the Net foundation of the Wisdom Podcast Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.