[Frequently Asked Questions] cookies use 1.Page with HttpContext Request, Response

xiaoxiao2021-03-06  41

The self-edged procedure is as follows

Using System; Using System.Web; Using System.Web.ui; Namespace Hnwl.config {///

/// cookdef's summary description. /// cookies related definition, and some inspections involving Cook, such as user login indication /// public class cookdef: Page {private httpcookie cook; public cookdef () {// // Todo: here Add the constructor logic //} public void New (string name) {cook = new HttpCookie (name);} public HttpCookie Req (string name) {cook = Request.Cookies [name]; return cook;} public void Append ( ) {Response.cookies.add (cook); // Tip this line after running}

The compilation process does not prompt the error, but System.Web.httpException appears after running: Response is not available in this context; revice.cookies [name] and response.cookies.add (cook) are changed to httpContext.current.Request.Cookies [ Name] and httpContext.current.response.cookies.add (cook) will return to normal.

Explanation: The response in Page can only be used in the page file (although the above definition is cookdef: page, but only as a common class), HTTPContext can use to use the current context data in any case.

转载请注明原文地址:https://www.9cbs.com/read-53455.html

New Post(0)