1: // Retrieve authentication type
2: string authenticationType = HttpContext.Current.User.Identity.AuthenticationType;
3:
4: // Replace output with a minimal output if authentication is anonymous or forms-based
5: if (!HttpContext.Current.Request.IsAuthenticated ||
6: String.IsNullOrEmpty(authenticationType) ||
7: authenticationType.Equals("Forms", StringComparison.InvariantCultureIgnoreCase)) 8: { 9:
10: // Load the ouputted HTML in memory
11: using (MemoryStream memoryStream = new MemoryStream())
12: using (StreamWriter streamWriter = new StreamWriter(memoryStream))
13: { 14: using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(streamWriter))
15: { 16: Control.GetType().InvokeMember(
17: "RenderControl",
18: BindingFlags.InvokeMethod
19: | BindingFlags.Instance
20: | BindingFlags.NonPublic,
21: null,
22: Control,
23: new object[] { htmlTextWriter, null }); 24: }
25:
26: // Flush the writer and rewind the stream
27: streamWriter.Flush();
28: memoryStream.Position = 0;
29:
30: // Read the stream as a string
31: using (StreamReader streamReader = new StreamReader(memoryStream))
32: { 33: string output = streamReader.ReadToEnd();
34:
35: // Remove core.js
36: string corePattern = @"\<script.+src\=.+core\.js.+\<\/script\>";
37:
38: output = Regex.Replace(output, corePattern, "", RegexOptions.IgnoreCase);
39:
40: // Replace init.js by a version excluding presence script
41: string initPattern = @"(\<script.+src\=\"")(init\.js)(\"".+\<\/script\>)";
42:
43: if (Regex.IsMatch(output, initPattern))
44: { 45: output = Regex.Replace(output,
46: initPattern,
47: String.Format("$1{0}$3", Page.ClientScript.GetWebResourceUrl( 48: typeof(ScriptLinkAdapter),
49: "ScriptLinkAdapter.ClientResources.SPInitNoPresence.js")),
50: RegexOptions.IgnoreCase);
51: }
52:
53: // Flush new content to response
54: writer.Write(output);
55: }
56: }
57:
58: // Registrations are done, so exit.
59: return;
60: }
61:
62: // Standard control rendering
63: Control.GetType().InvokeMember(
64: "RenderControl",
65: BindingFlags.InvokeMethod
66: | BindingFlags.Instance
67: | BindingFlags.NonPublic,
68: null,
69: Control,
70: new object[] { writer, null });