If I've understood you correctly, you're making a request from one page in your site to another, and you want to send the cookies from the current HttpRequest
with your WebRequest
?
In that case, you'll need to manually copy the cookies to the CookieContainer
:
For Each key As String In Request.Cookies.AllKeys
Dim sourceCookie As HttpCookie = Request.Cookies(key)
Dim destCookie As New Cookie(sourceCookie.Name, sourceCookie.Value, sourceCookie.Path, "localhost")
destCookie.Expires = sourceCookie.Expires
destCookie.HttpOnly = sourceCookie.HttpOnly
destCookie.Secure = sourceCookie.Secure
oCookies.Add(destCookie)
Next
NB: You'll either need to make the ReadUrl
function non-Shared
, or pass the current HttpRequest
as a parameter.
You'll also need to make sure the calling page has EnableSessionState="false"
in the <%@ Page ... %>
directive, otherwise the page you're calling will hang trying to obtain the session lock.