What is the difference between httpcontext. Current. cache and httpruntime. cache?

Source: Internet
Author: User

What is the difference between httpcontext. Current. cache and httpruntime. cache?

Static managecache ()
{
Httpcontext context = httpcontext. Current;
If (context! = NULL)
{
_ Cache = context. cache;
}
Else
{
_ Cache = httpruntime. cache;
}
}

----------------------------------------

They refer to the same object, in a request, page. cache and httpcontext. current. the cache is effective. The difference between the two is generally determined by the place you call. If the two are in the page, use the page. cache. in asax or your own function, use the latter

However, if you need to access an event, such as a timer-based processing function, because there is no httpcontext at the time, use httpruntime. Cache

-------------------------------------------

What is the difference between httpcontext. Current. Items and httpcontext. Current. cache?

Where are the specific usage of these two things?

Httpcontext. Current. items is only good for the current request, httpcontext. Current. cache is good as long as the cache is not expired

Httpcontext. Current. items ["hello"] = object;

See how to use httpcontext. Current. cache here:
Http://www.fawcette.com/Archives/premier/mgznarch/vbpj/2001/11nov01/an0111/an0111-1.asp

Httpcontext. current. items is for the current HTTP request, that is, data can be shared in an HTTP request. A typical usage is to obtain data on An ASPX page and save it in context. pages in items are shared with the current HTTP request, such as user controls. The best example is the ibuyspy portal. You can check its source code. The data stored in the cache can be used for rebuild.Program.

However, I have seen a lot of programs handle this.
Using system. Web;

Namespace lukiya. uoo. webui
{
Public class test
{
Public static mappath (httpcontext context, string URL)
{
Return context. mappath (URL );
}
}
}

 

Httpcontext. Current indicates the context object corresponding to the current httprequest. My question is: does the httpcontext. Current object change when one page is transferred to another in webapplication ??
I found that many programs store the login user information to httpcontext. current. user or httpcontext. current. in items, it seems that httpcontext. current does not change throughout the application process and does not know whether it is understood correctly.

In addition, what are the advantages of storing Login User information in context and in session.

Invalid.
Will change.

If you want to keep the entire application unchanged, you should use the application to save it.

However, if httpcontext. Current Changes During page Jump, Why do many programs still use it to save information?
I feel unchanged.

That is to share data in a request.
For example:

Http://jiezhi.cnblogs.com/archive/2005/01/12/90751.html

I seem to understand.
The httpcontext. Current object is only for one httprequest (a specific page of a specific user). After the page jumps, the object changes.

However, httpcontext. Current. User is related to thread, that is, a specific user corresponds to a thread. Even if the page jumps, httpcontext. Current. User remains unchanged.

I don't know, right? please correct me.

Each time the customer sends an httprequest, The httpruntime object creates an httpcontext object, so each time it is different.

Thank you for understanding.
Httpcontext. Current. user must exist in the cookie or session, and be written every time the acquirerequeststateCodeOnly httpcontext can be read and written.

Htttpcontext itself is stateless and cannot transmit information between pages.

>>> Httpcontext. Current. user must actually exist in the cookie or session. Each time the acquirerequeststate is acquirerequeststate, the Code must be read and written to httpcontext.
It is not a cookie or session, but an in-process object. However, if forms authentication is used, the current user is always identified by reading cookies. The last short sentence is correct.

>>> But httpcontext. Current. User is related to thread. That is to say, a specific user corresponds to a thread. Even if the page jumps, httpcontext. Current. User remains unchanged.
Completely incorrect. It has nothing to do with threading.

>>> What are the advantages of storing Login User information in Context/cookie and in session?
Session is also implemented by Cookie, while HTTP is stateless, so ..

It doesn't mean that it has nothing to do with threading. In fact, system. Threading. thread. currentprincipal and System. Web. httpcontext. Current. User are synchronized.
However, the idea of a single user thread is absolutely wrong. If you understand the HTTP model

 

-------

This class is actually processed by systemframework.
1. Add a reference to system. web in the sysframework class.
2. Define static variables as follows:
Public static system. Web. httpcontext;
3. initialize httpcontext in application_start of Global. asax
Then you can directly reference sysframework. httpcontext. Current in the data access layer.

-----

I really don't understand such a statement "Search searchform = (Search) Context. Handler.

The above statement is very strange:

1. The search class, interface, structure, enumeration, and enum are not defined in the source program. This is not found in msdn.
2. Secondly, I don't understand what context is. The first time I saw it, although it was introduced in msdn, I didn't quite understand it.

The above two questions are for your help.

This is generally used in the page after server. Transfer.

Search should be a page-based class. If your stuff can run, this class should exist. Check it again, or use idasm. EXE to open your DLL.

Context refers to httpcontext. Current, and handler refers to the ihttphandler corresponding to the request. Here, it should refer to the page corresponding to the URL of the current request

Indeed, search is a page-based class,

To be in EMP. the transfer method is used in aspx, while the context. handler can be understood as AA on the current page. the handle of the previous page of aspx .. in this way, the value of the control or variable in the EMP page can be obtained in the source...

page handle, used to identify the previous page

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.