Previous Topic: Access HttpRequest ObjectNext Topic: User Exits


Use HttpResponse Object

Using methods and properties of the HttpResponse class is risky and could potentially cause runtime abends. For example, invoking the methods Redirect or Write, or WriteFile circumvents essential execution paths in the CA Gen runtime that impact history handling. Accessing certain Properties may also cause the application server to throw exceptions.

Follow these steps:

  1. Design an External Action Block (EAB).
  2. Use the EAB in the Pstep or Action Block where access to the response is required.
  3. Design the views and attributes that hold the information needed to set the request.
  4. Generate the EAB.
  5. Add the following in the EAB method where user code is expected:

    // User written code should be inserted here.

    HttpResponse res = (HttpResponse)IefRuntimeParm2.GetResponse();
    
  6. As an example, do the following to set a cookie:
    HttpCookie cookie = new HttpCookie("LastVisit");
    cookie.Value = DateTime.Now.ToString();
    cookie.Expires = DateTime.Now.AddDays(1);
    res.Cookies.Add(cookie);
    
  7. Compile the application.