. Net

Source: Internet
Author: User
Tags current time httpcontext

Physical path on the server disk: HttpRuntime. AppDomainAppPath
Virtual Program path:
HttpRuntime. AppDomainAppVirtualPath

 


Any method related to Request/HttpContext. Current can only be used when there is a Request context or page.
That is, when no request context is available, HttpContext. Current is null, and the method mentioned above is always available.

 

The access to global Cache objects is also true.


Private
Void responseHtml ()
...{
        
System. Text. StringBuilder sb = new
System. Text. StringBuilder ();
        
Sb. Append (string. Format ("Current time:
{0 }",
Server. HtmlEncode (DateTime. Now. ToString ())));
        
Sb. Append ("<br/> ");
        
Sb. Append (string. Format ("virtual path of the current request:
{0} ", Server. HtmlEncode (Request. CurrentExecutionFilePath )));
        
Sb. Append ("<br/> ");
        
Sb. Append (string. Format ("obtain the root directory path of the current application: {0 }",
Server. HtmlEncode (Request. ApplicationPath )));
        
Sb. Append ("<br/> ");
        
Sb. Append (string. Format ("virtual path of the current request:
{0} ", Server. HtmlEncode (Request. FilePath )));
        
Sb. Append ("<br/> ");
        
Sb. Append (string. Format ("virtual path of the current request:
{0} ", Server. HtmlEncode (Request. Path )));
        
Sb. Append ("<br/> ");
        
Sb. Append (string. Format ("obtain the physical file system path of the root directory of the currently running application: {0 }",
Server. HtmlEncode (Request. PhysicalApplicationPath )));
        
Sb. Append ("<br/> ");
        
Sb. Append (string. Format ("Get and request URL
Corresponding physical file system path: {0 }",
Server. HtmlEncode (Request. PhysicalApplicationPath )));
        
Sb. Append ("<br/> ");
        
Response. Write (sb. ToString ());
    
}
}


Output: Current time: 2007-08-30
11:03:49
The virtual path of the current request:/aDirectory/Sample/responseHtml. asp tutorial x
Obtain the root directory path of the current application:
/ADirectory
The virtual path of the current request:/aDirectory/Sample/responseHtml. aspx
The virtual path of the current request:
/ADirectory/Sample/responseHtml. aspx
Obtain the physical file system path of the root directory of the currently running application: E: Visual
Maxcompute Studio 2005
Obtain the physical file system path corresponding to the requested URL: E: Visual Studio 2005 aDirectory

When the url contains parameters, you can use:
HttpContext. Current. Request. Url. PathAndQuery. ToString ()//

 

This page address: Request. URL;

 


Last page address:
Request. UrlReferrer

Request. ServerViables ["http_referer"]
Request. RawUrl

Request. RawUrl. QueryAndPath

System. IO. Path. GetFileName (Request. FilePath. ToString ())

 

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.