Skip to content

Commit 3493917

Browse files
authored
Update AuthorizationHttpModule.cs
Signed-off-by: Joachim Fosse <56757601+joaf123@users.noreply.github.com>
1 parent 659a52c commit 3493917

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

AuthorizationHttpModule.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ public class RequiresAuthenticationAttribute : Attribute { }
1717
/// Attribute based forms authentication verification module.
1818
/// </summary>
1919
public class AttributeBasedFormsAuthenticationModule : IHttpModule {
20+
public static bool useAuthorization = false;
2021
/// <summary>
2122
/// Inits the AttributeBasedFormsAuthentication Module.
2223
/// </summary>
2324
/// <param name="application">HttpApplication Parameter</param>
2425
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+
}
2631
}
2732

2833
/// <summary>
@@ -89,7 +94,7 @@ private void OnPostAuthorizeRequest(object sender, EventArgs e) {
8994
string methodName = segments[1]; // Extract the part after .asmx/ as the method name
9095
string asmxUrlWithoutMethod = requestUrl.Replace("/" + methodName, ""); // Remove the method name from the URL
9196

92-
var codeBehindPath = GetCodeBehindPathFromASMXUrl(asmxUrlWithoutMethod);
97+
var codeBehindPath = GetCodeBehindPathFromASMXUrl(asmxUrlWithoutMethod);
9398

9499
if (!string.IsNullOrEmpty(codeBehindPath)) {
95100
dynamic _handler = context.CurrentHandler;
@@ -233,3 +238,9 @@ private static string GetWebMethodNameFromRequest(HttpRequest request) {
233238
return slashIndex >= 0 ? pathInfo.Substring(0, slashIndex) : pathInfo;
234239
}
235240
}
241+
242+
public static class HttpApplicationExtensions {
243+
public static void UseAuthorization(this HttpApplication application) {
244+
AttributeBasedFormsAuthenticationModule.useAuthorization = true;
245+
}
246+
}

0 commit comments

Comments
 (0)