1- using System ;
1+ using System ;
22using System . Reflection ;
33using System . Web ;
44using System . Web . Compilation ;
55using System . Web . Security ;
66using System . Web . UI ;
7-
7+ /// <summary>
8+ /// Verify authorization on call to WebMethods or Pages with the attribute: <RequiresAuthentication> (VB) | [RequiresAuthentication] (C#).
9+ /// </summary>
810[ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Class ) ]
911public class RequiresAuthenticationAttribute : Attribute { }
1012
13+ /// <summary>
14+ /// Attribute based forms authentication verification module.
15+ /// </summary>
1116public class AttributeBasedFormsAuthenticationModule : IHttpModule {
17+ /// <summary>
18+ /// Inits the AttributeBasedFormsAuthentication Module.
19+ /// </summary>
20+ /// <param name="application">HttpApplication Parameter</param>
1221 public void Init ( HttpApplication application ) {
1322 application . PostMapRequestHandler += OnPostAuthorizeRequest ;
1423 }
1524
25+ /// <summary>
26+ /// Disposes the AttributeBasedFormsAuthentication Module
27+ /// </summary>
1628 public void Dispose ( ) {
1729 // Clean up resources, if any
1830 }
1931
32+ /// <summary>
33+ /// Authorize request.
34+ /// </summary>
35+ /// <param name="sender">Sender Parameter</param>
36+ /// <param name="e">EventArgs Parameter</param>
2037 private void OnPostAuthorizeRequest ( object sender , EventArgs e ) {
2138 var app = ( HttpApplication ) sender ;
2239 var context = app . Context ;
@@ -43,15 +60,24 @@ private void OnPostAuthorizeRequest(object sender, EventArgs e) {
4360 }
4461 }
4562
63+ /// <summary>
64+ /// Deny access.
65+ /// </summary>
66+ /// <param name="context">The context.</param>
4667 private static void DenyAccess ( HttpContext context ) {
4768 context . Response . StatusCode = 401 ;
4869 context . Response . SuppressContent = true ;
4970 context . Response . End ( ) ;
5071 }
5172
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>
5278 private static string GetWebMethodNameFromRequest ( HttpRequest request ) {
5379 var pathInfo = request . PathInfo . TrimStart ( '/' ) ;
5480 var slashIndex = pathInfo . IndexOf ( '/' ) ;
5581 return slashIndex >= 0 ? pathInfo . Substring ( 0 , slashIndex ) : pathInfo ;
5682 }
57- }
83+ }
0 commit comments