I have the following code that reuses a CookieContainer, which logs in on the first request, but just uses the cookie container for requests after.
After a certain period of time, when the hosting site will provide a session timeout, I will need to log in again.
Q: Can I determine (with a cookie container object) if a timeout has occurred, or is it better to determine if it came from an HttpWebResponse that contains text such as "session timeout". What is the best way to do this?
private static CookieContainer _cookieContainer; private static CookieContainer CurrentCookieContainer { get { if (_cookieContainer == null || _cookieContainer.Count == 0) { lock (_lock) { if (_cookieContainer == null || _cookieContainer.Count == 0) {
And then this method calls the container:
public static string SomeMethod(SomeParams p) { HttpWebRequest request_thirdPartyEnquiryDetails = (HttpWebRequest)WebRequest.Create(thirdPartyEnquiryDetails); CookieContainer cookieContainer = CurrentCookieContainer; request_thirdPartyEnquiryDetails.CookieContainer = cookieContainer;
source share