-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAbandonSession.cs
More file actions
57 lines (47 loc) · 1.3 KB
/
AbandonSession.cs
File metadata and controls
57 lines (47 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Web;
using System.Web.Security;
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
if (FormsAuthentication.Authenticate("username", "password"))
{
ctx.Session["foo"] = "bar"; // BAD: Session has not been abandoned
ctx.Session.Abandon();
ctx.Session["foo"] = "bar"; // GOOD: Session is abandoned
}
else
{
ctx.Session["foo"] = "bar"; // GOOD: Logon didn't succeed
}
}
public bool IsReusable => true;
}
public class Handler2 : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
if (Membership.ValidateUser("username", "password"))
{
AbandonSession(ctx);
ctx.Session["foo"] = "bar"; // GOOD: Session is abandoned (indirectly)
}
}
void AbandonSession(HttpContext ctx)
{
ctx.Session.Clear();
}
public bool IsReusable => true;
}
public class Handler3 : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
if (Membership.ValidateUser("username", "password"))
{
ctx.Session["foo"] = "bar"; // BAD: Session not abandoned
}
ctx.Session["foo"] = "bar"; // BAD: here as well
}
public bool IsReusable => true;
}