I am trying to set the path of a cookie but I am always recieving the error:
CookieException: The 'Path'='/applogin'
part of the cookie is invalid.
the code looks like this:
Cookie newCookie = new Cookie("JSESSIONID", session.SessionId, "/applogin", "domain.com");
newCookie.Secure = true;
webRequest.CookieContainer.Add(new Uri(@"https://domain.com"), newCookie);
the exception is then throwen on the last line... can anyone point me in the right direction?
In your case you have two urls: one is a https://domain.com
and second one is a https://domain.com/applogin
. Let's assume that CookieContainer contains your cookie for path /applogin. This means that if you will try to retrieve list of cookies for url https://domain.com/applogin
- you will get one cookie. If you will try to retrieve cookies for url https://domain.com
- you will get 0 cookies.
Now let's look on your sample. You have a cookie for https://domain.com/applogin
and you are trying to add it to CookieContrainer for url https://domain.com
. CookieContainer verifies that this cookie cannot be used for specific url, because it was issues for different url. In your case you need to change line where you add cookie:
webRequest.CookieContainer.Add(new Uri(@"https://domain.com/applogin"), newCookie);
Or I guess you want to use this cookie for whole domain.com - then you need to change how you create it to
Cookie newCookie = new Cookie("JSESSIONID", session.SessionId, "/", "domain.com");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With