Imagine a hypothetical situation when you need to give the user files with, say, some unique to each user's data, and it is ready to give the files, rather than to generate on the fly. The simplest and most obvious option would be to create a handler that will be called for inquiries type "* _report.pdf", but for this we need to understand whether it is possible to give the user a file that it requests, or it belongs to another user.
Transmit ID explicitly not only ideologically correct, but just not nice, and save the file to the link type 10102_u323467_report.pdf? SessId = 05446DA8F736B29A will be saved by default to the same "crooked" name.
It is much easier to put the ID in session and get it in the handler from there. To Session object was available, we need to handler inherited not only on the interface IHttpHandler, but odes one of the interfaces IRequiresSessionState or IReadOnlySessionState depending on whether we need read-only access (IReadOnlySessionState) or read-write (IRequiresSessionState ). In fact, written in the session object, you can just about anything, in any case, the only difference is that when using IReadOnlySessionState at the end of processing the request session data are not stored.
Deriving from these interfaces do not require the implementation of any method, as they are both marker, that is, containing no more than one method, and are only used to mark the runtime .Net need to create a session object for our handler.
And at the same time remind you what IsReusable. During the processing of each request handler objects completely pass all stages from creation to delete from memory by the garbage collector. So, property IsReusable says runtime on whether to process a request, after removing an object, or it can be saved and used to process subsequent requests.
Regarding our example, IsReusable is true would have been useful if we'd had ReportDownloadHandler class constructor, which would have created some kind of order to process the data structure used or to other expensive operations.
Only when using IsReusable = true must be checked to the end of the execution of the method ProcessRequest state object would be the same as at the beginning of the query.
Transmit ID explicitly not only ideologically correct, but just not nice, and save the file to the link type 10102_u323467_report.pdf? SessId = 05446DA8F736B29A will be saved by default to the same "crooked" name.
It is much easier to put the ID in session and get it in the handler from there. To Session object was available, we need to handler inherited not only on the interface IHttpHandler, but odes one of the interfaces IRequiresSessionState or IReadOnlySessionState depending on whether we need read-only access (IReadOnlySessionState) or read-write (IRequiresSessionState ). In fact, written in the session object, you can just about anything, in any case, the only difference is that when using IReadOnlySessionState at the end of processing the request session data are not stored.
Deriving from these interfaces do not require the implementation of any method, as they are both marker, that is, containing no more than one method, and are only used to mark the runtime .Net need to create a session object for our handler.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > public class SessionEnabledHandler : IHttpHandler, IRequiresSessionState</span> public class SessionEnabledHandler: IHttpHandler, IRequiresSessionState</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >{</span> {</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > public bool IsReusable</span> public bool IsReusable</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >{</span> {</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > get </span> get </span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >{</span> {</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > return true ;</span> return true ;</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >}</span> }</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >}</span> }</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > public void ProcessRequest(HttpContext context)</span> public void ProcessRequest (HttpContext context)</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >{</span> {</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > string sessionMarket = ( string )context.Session[ "SessionData" ];</span> string sessionMarket = ( string ) context.Session [ "SessionData" ];</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > string file = context.Request.RawUrl;</span> string file = context.Request.RawUrl;</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" > //после чего можно проверить имеет ли данный пользователь доступ к запрошенному файлу</span> // then you can check whether the user has access to the requested file</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >}</span> }</span> <span class = "notranslate" onmouseover= "_tipon(this)" onmouseout= "_tipoff()" ><span class = "google-src-text" style= "direction: ltr; text-align: left" >}</span> }</span> |
And at the same time remind you what IsReusable. During the processing of each request handler objects completely pass all stages from creation to delete from memory by the garbage collector. So, property IsReusable says runtime on whether to process a request, after removing an object, or it can be saved and used to process subsequent requests.
Regarding our example, IsReusable is true would have been useful if we'd had ReportDownloadHandler class constructor, which would have created some kind of order to process the data structure used or to other expensive operations.
Only when using IsReusable = true must be checked to the end of the execution of the method ProcessRequest state object would be the same as at the beginning of the query.
0 коммент.:
Post a Comment