Server.MapPath query path That's a few things.

Source: Internet
Author: User

The main summary Server.MapPath the use of this method and the use of the scene, not when it is suitable for use;

1, realize the function:

Server.MapPath can obtain the physical path of the specified URL relative to the server, and on the IIS service side, it can obtain the physical path of the file according to its file name;

2, there is a command space:

System.Web.HttpContext.Current.Server.MapPath and System.web.MVC.Control.Server.Mapth;

3, the use of:

Since it's System.Web.HttpContent. It is also timely to show that the method can only be used in http.web, not the environment system will throw an error; what does a non-web environment mean? So, for example, when we use threads to handle a business logic, you use that method when you're using it, and that's an error that you're out of the web environment. Therefore, depending on the situation, the physical address of the virtual directory is obtained, and the method is very effective.

4. Matters needing attention:

System. Web.HttpContext.Current.Server.MapPath ("Mypic") is to obtain the current peer directory address;

System. Web.HttpContext.Current.Server.MapPath (".. /mypic ") is to obtain the current parent directory address;

Use the time need to be cautious;

Server.MapPath query path That's a few things.

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.