1
- using System ;
1
+ using System ;
2
2
using System . Reflection ;
3
3
using System . Web ;
4
4
using System . Web . Compilation ;
5
5
using System . Web . Security ;
6
6
using System . Web . UI ;
7
-
7
+ /// <summary>
8
+ /// Verify authorization on call to WebMethods or Pages with the attribute: <RequiresAuthentication> (VB) | [RequiresAuthentication] (C#).
9
+ /// </summary>
8
10
[ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Class ) ]
9
11
public class RequiresAuthenticationAttribute : Attribute { }
10
12
13
+ /// <summary>
14
+ /// Attribute based forms authentication verification module.
15
+ /// </summary>
11
16
public class AttributeBasedFormsAuthenticationModule : IHttpModule {
17
+ /// <summary>
18
+ /// Inits the AttributeBasedFormsAuthentication Module.
19
+ /// </summary>
20
+ /// <param name="application">HttpApplication Parameter</param>
12
21
public void Init ( HttpApplication application ) {
13
22
application . PostMapRequestHandler += OnPostAuthorizeRequest ;
14
23
}
15
24
25
+ /// <summary>
26
+ /// Disposes the AttributeBasedFormsAuthentication Module
27
+ /// </summary>
16
28
public void Dispose ( ) {
17
29
// Clean up resources, if any
18
30
}
19
31
32
+ /// <summary>
33
+ /// Authorize request.
34
+ /// </summary>
35
+ /// <param name="sender">Sender Parameter</param>
36
+ /// <param name="e">EventArgs Parameter</param>
20
37
private void OnPostAuthorizeRequest ( object sender , EventArgs e ) {
21
38
var app = ( HttpApplication ) sender ;
22
39
var context = app . Context ;
@@ -43,15 +60,24 @@ private void OnPostAuthorizeRequest(object sender, EventArgs e) {
43
60
}
44
61
}
45
62
63
+ /// <summary>
64
+ /// Deny access.
65
+ /// </summary>
66
+ /// <param name="context">The context.</param>
46
67
private static void DenyAccess ( HttpContext context ) {
47
68
context . Response . StatusCode = 401 ;
48
69
context . Response . SuppressContent = true ;
49
70
context . Response . End ( ) ;
50
71
}
51
72
73
+ /// <summary>
74
+ /// Gets the web method name from request.
75
+ /// </summary>
76
+ /// <param name="request">The request.</param>
77
+ /// <returns>WebMethod name as string.</returns>
52
78
private static string GetWebMethodNameFromRequest ( HttpRequest request ) {
53
79
var pathInfo = request . PathInfo . TrimStart ( '/' ) ;
54
80
var slashIndex = pathInfo . IndexOf ( '/' ) ;
55
81
return slashIndex >= 0 ? pathInfo . Substring ( 0 , slashIndex ) : pathInfo ;
56
82
}
57
- }
83
+ }
0 commit comments