First: Cross-origin. The method for obtaining the path of other website files is System. AppDomain. CurrentDomain. BaseDirectory.
Second, developers do not know which directory the website will be deployed, so they cannot write absolute paths. They only know the relative paths relative to the root directory of the website, to locate the file path, you can only call HttpContext. current. request. mapPath or HttpContext. current. server. mapPath to obtain the absolute path of the file. If HttpContext. Current returns null, how can I access the file?
Answer: System. AppDomain. CurrentDomain. BaseDirectory
Third: Use HttpContext for security
HttpContext context = HttpContext. Current; if (context! = Null) {// can run here, it must be processing ASP.. appendLine ("Url:" + context. request. rawUrl); // you can do it yourself. }
It is a judgment that solves some null problems, so please forget the following unsafe statements.
Conclusion: HttpContext: The current thread refers to the thread related to the current request.
1. Timer callback.
2. Cache removal notification.
3. Callback is completed asynchronously in APM mode.
4. Actively create a thread or submit the task to the thread pool for execution.
In Case 1, 2, 3, access HttpContext. Current will return null.
3. There are two solutions:
1. Add a field to the type to save the reference of HttpContext (before the Asynchronous Start ).
2.
Assign HttpContext to the last parameter (object state) of the BeginXXX Method)
We recommend that you first select the second method, because it can prevent accidental use of data members during maintenance by others in the future.
4. It is not the current thread, so you do not need to discuss it.
Ths: http://www.cnblogs.com/fish-li/archive/2013/04/06/3002940.html