I have a function that expect HttpRequest as parameter:
public string Read(HttpRequest req)
{
if (req.Headers["X-Requested-With"] == "XMLHttpRequest")
{
return req.Headers[ConfigurationManager.AppSettings["ajaxsession"]];
}
return req.Cookies[ConfigurationManager.AppSettings["cookiename"]];
}
I wrote a unit test
[Test]
public void ReadSessionToken_BrowserRequest_ExpectSidToken()
{
var repo = new DefaultHttpContext();
}
My question is, how to add a cookie to repo.Request.Cookies
?
I didn't test but in github repo there is a test for set and get cookie:
var newCookies = new[] { "name0=value0%2C", "%5Ename1=value1" };
request.Headers["Cookie"] = newCookies;
Update
Tested and worked.
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