| View previous topic :: View next topic |
| Author |
Message |
pma Newbie

Joined: 15 Jun 2010 Posts: 8
|
Posted: Tue Jun 15, 2010 10:06 am Post subject: Ivonna, session state problem |
|
|
Hi,
I'm having a problem with disappearing session state between requests.
There is an ancient topic regarding the subject (How to simulate session?) and test case presented there works fine.
However, test fails when I issue an extra request. It seems that Session_Start event is triggered one more time and test fails:
| Code: |
[Test, Isolated]
public void KeepsSessionValuesAcrossMultipleRequests2()
{
TestSession session = new TestSession();
WebRequest request = new WebRequest("test/Page1.aspx");
request.EventHandlers.Page_PreInit = delegate(object sender, System.EventArgs e)
{
HttpSessionState httpsession = HttpContext.Current.Session;
httpsession["test"] = "testvalue";
};
session.ProcessRequest(request); //1st Session_Start
request = new WebRequest("test/Page1.aspx");
request.EventHandlers.Page_PreInit = delegate(object sender, System.EventArgs e)
{
HttpSessionState httpsession = HttpContext.Current.Session;
Assert.AreEqual("testvalue", httpsession["test"], "Invalid session value");
};
session.ProcessRequest(request);
WebRequest thirdRequest = new WebRequest("test/Page1.aspx");
thirdRequest.EventHandlers.Page_PreInit = delegate(object sender, System.EventArgs e)
{
HttpSessionState httpsession = HttpContext.Current.Session;
Assert.AreEqual("testvalue", httpsession["test"], "Invalid session value on 3rd request");
};
session.ProcessRequest(thirdRequest); //2nd Session_Start, session is empty - test fails
}
|
It seems that cookie containing session state id is not sent to server. Am I doing something wrong here?
I'm running Ivonna 2.1.1.22205 and TypeMock Isolator 6.0.3.0.
Thanks, |
|
| Back to top |
|
 |
ulu Advanced

Joined: 18 Apr 2007 Posts: 15
|
Posted: Wed Jun 16, 2010 10:51 am Post subject: |
|
|
Hi,
You have discovered a bug in Ivonna. The problem is that the authentication cookie is not being sent with the third request.
I'll publish the fix today and let you know.
Artem |
|
| Back to top |
|
 |
ulu Advanced

Joined: 18 Apr 2007 Posts: 15
|
|
| Back to top |
|
 |
pma Newbie

Joined: 15 Jun 2010 Posts: 8
|
Posted: Thu Jul 08, 2010 4:53 pm Post subject: |
|
|
Hi,
Fix works perfectly, but there seems to be a problem when application adds additional cookies to response.
Please take a look at test:
| Code: |
[Test, Isolated]
public void CookiesWrittenOnFirstRequestShouldBeAvailableOnSecondRequest()
{
const string url = "/testpage.aspx";
const string additionalCookieName = "mc_1";
var session = new TestSession();
session.SetUser("foo", new string[0]);
var sessionKeyFromFirstRequest = "";
var firstRequest = new WebRequest(url);
firstRequest.EventHandlers.Page_PreRender += (s, e) =>
{
var page = (Page) s;
sessionKeyFromFirstRequest = page.Session.SessionID;
var newCookie = new HttpCookie(additionalCookieName);
newCookie.Values.Add("10394", "1");
page.Response.Cookies.Add(newCookie);
};
session.ProcessRequest(firstRequest);
var secondRequest = new WebRequest(url);
secondRequest.EventHandlers.Page_Init += (s, e) =>
{
var page = (Page)s;
var cookieHeaders = "Cookie header: " + page.Request.Headers["Cookie"].ToString();
Assert.AreEqual(sessionKeyFromFirstRequest, page.Session.SessionID, cookieHeaders);
Assert.NotNull(page.Request.Cookies[additionalCookieName], cookieHeaders);
};
session.ProcessRequest(secondRequest);
}
|
It seems like there is a problem when cookies are sent back to ASP .NET.
E.g. cookie header instead of:
Cookie: ASP.NET_SessionId=51pncynqyhc3iy452ny1cnmm; mc_1=10394
looks like:
Cookie: ASP.NET_SessionId=51pncynqyhc3iy452ny1cnmm:mc_1=10394
Note ':' instead of '; '
This totally confuses ASP .NET, session starts again and 'mc_1' cookie gets overwritten. |
|
| Back to top |
|
 |
|