-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobal.asax
More file actions
96 lines (76 loc) · 3.06 KB
/
Global.asax
File metadata and controls
96 lines (76 loc) · 3.06 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<%@ Application Language="C#" %>
<%@import namespace="Microsoft.IdentityModel.Web"%>
<%@import namespace="Microsoft.IdentityModel.Tokens"%>
<%@import namespace="Microsoft.IdentityModel.Web.Configuration"%>
<%@import namespace="System.Collections.Generic"%>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated;
}
private void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
List<CookieTransform> sessionTransforms =
new List<CookieTransform>(
new CookieTransform[]
{
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(
e.ServiceConfiguration.ServiceCertificate),
new RsaSignatureCookieTransform(
e.ServiceConfiguration.ServiceCertificate)
});
SessionSecurityTokenHandler sessionHandler =
new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception ex = Context.Error;
if(ex.Message.StartsWith("ID3206:"))
{
if (!(Request.ApplicationPath.EndsWith("/")))
{
Response.Redirect(Request.Path + "/");
}
}
else if (ex.Message.StartsWith("ID1014:"))
{
//corrupted SSO cookie
//We flush these cookies, so the user needs to log in again instead of throwing an error
FlushSSOCookies();
}
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
void FlushSSOCookies()
{
int limit = Request.Cookies.Count;
for (int i=0; i<limit; i++)
{
String cookieName = Request.Cookies[i].Name;
if (cookieName.StartsWith("FedAuth") || cookieName.StartsWith("ASP.NET_SessionId"))
{
HttpCookie aCookie = new HttpCookie(cookieName);
aCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(aCookie);
}
}
Response.Redirect(Request.Path);
}
</script>