asp.net get URL path method

Source: Internet
Author: User

The main solution is to rely on HttpContext objects, such as

Httpcontext.current.request.physicalpath; Gets the full physical path of the current page. For example f:xfu.nsqsprojectwebsitedefault.asp Tutorial X
Httpcontext.current.request.physicalapplicationpath; Get the physical path that the current program is running, like F:xfu.nsqsprojectwebsite.
Httpcontext.current.server.mappath (@ ""); This is the MapPath on the page. Same usage

Httpruntime.appdomainapppath//This is newly discovered, very easy to use.

Another is to handle calling DLL files in the ASP.net tutorial, and DLL files that want to know the working directory of the current Web site can use
System.appdomain.currentdomain.basedirectory


Simple Three Ways

Xi asp.net upload file, found that there are three ways to get the current web directory physical path:

Method One:

string spath = System.io.path.getdirectoryname (Page.request.physicalpath)

Method Two:

string spath = System.web.httpcontext.current.request.mappath ("images/")

("images/") is any directory under the current virtual directory

Method Three:

string spath = Page.server.mappath ("images/"); ("images/") is any directory under the current virtual directory

Another: Get the file name in the full path

string sfile = System.io.path.getfilename (sfile);

Gets the full path of the current process, including the filename (process name).

string str = This.gettype (). assembly.location;

Result:x:xxxxxxxxx.exe (. exe file directory +.exe file name)

Gets the full path of the main module that is associated with the currently active process, including the filename (process name), for the new process component.

string str = system.diagnostics.process.getcurrentprocess (). Mainmodule.filename;

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.