@@ -17,12 +17,17 @@ public class RequiresAuthenticationAttribute : Attribute { }
17
17
/// Attribute based forms authentication verification module.
18
18
/// </summary>
19
19
public class AttributeBasedFormsAuthenticationModule : IHttpModule {
20
+ public static bool useAuthorization = false ;
20
21
/// <summary>
21
22
/// Inits the AttributeBasedFormsAuthentication Module.
22
23
/// </summary>
23
24
/// <param name="application">HttpApplication Parameter</param>
24
25
public void Init ( HttpApplication application ) {
25
- application . PostMapRequestHandler += OnPostAuthorizeRequest ;
26
+ // Check if it should be initialized
27
+ if ( useAuthorization ) {
28
+ // Your initialization logic here
29
+ application . PostMapRequestHandler += OnPostAuthorizeRequest ;
30
+ }
26
31
}
27
32
28
33
/// <summary>
@@ -89,7 +94,7 @@ private void OnPostAuthorizeRequest(object sender, EventArgs e) {
89
94
string methodName = segments [ 1 ] ; // Extract the part after .asmx/ as the method name
90
95
string asmxUrlWithoutMethod = requestUrl . Replace ( "/" + methodName , "" ) ; // Remove the method name from the URL
91
96
92
- var codeBehindPath = GetCodeBehindPathFromASMXUrl ( asmxUrlWithoutMethod ) ;
97
+ var codeBehindPath = GetCodeBehindPathFromASMXUrl ( asmxUrlWithoutMethod ) ;
93
98
94
99
if ( ! string . IsNullOrEmpty ( codeBehindPath ) ) {
95
100
dynamic _handler = context . CurrentHandler ;
@@ -233,3 +238,9 @@ private static string GetWebMethodNameFromRequest(HttpRequest request) {
233
238
return slashIndex >= 0 ? pathInfo . Substring ( 0 , slashIndex ) : pathInfo ;
234
239
}
235
240
}
241
+
242
+ public static class HttpApplicationExtensions {
243
+ public static void UseAuthorization ( this HttpApplication application ) {
244
+ AttributeBasedFormsAuthenticationModule . useAuthorization = true ;
245
+ }
246
+ }
0 commit comments