Skip to content

Commit 875e88c

Browse files
claudiamurialdoBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:feature/canonical-app-casing-module' into beta
1 parent af20b4f commit 875e88c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpModules.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,41 @@ void IHttpModule.Dispose()
316316
}
317317
#endregion
318318
}
319+
public class GXVirtualPathCasingModule : IHttpModule
320+
{
321+
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<GXVirtualPathCasingModule>();
322+
323+
public void Init(HttpApplication context)
324+
{
325+
context.BeginRequest += OnBeginRequest;
326+
}
327+
328+
public void Dispose()
329+
{
330+
}
331+
332+
private static void OnBeginRequest(object sender, EventArgs e)
333+
{
334+
HttpContext context = ((HttpApplication)sender).Context;
335+
string appPath = HttpRuntime.AppDomainAppVirtualPath;
336+
if (string.IsNullOrEmpty(appPath) || appPath == "/")
337+
return;
338+
339+
string rawUrl = context.Request.RawUrl;
340+
if (rawUrl == null)
341+
return;
342+
343+
if (!rawUrl.StartsWith(appPath, StringComparison.Ordinal) &&
344+
rawUrl.StartsWith(appPath, StringComparison.OrdinalIgnoreCase))
345+
{
346+
string canonical = appPath + rawUrl.Substring(appPath.Length);
347+
GXLogging.Debug(log, "Redirecting non-canonical app path '", rawUrl, "' to '", canonical, "'");
348+
#pragma warning disable SCS0027 // Open redirect: target is built from AppDomainAppVirtualPath (server config) and the original request path, always same-origin relative URL
349+
context.Response.RedirectPermanent(canonical, true);
350+
#pragma warning restore SCS0027
351+
}
352+
}
353+
}
319354
public class GXRewriter : IHttpModule
320355
{
321356
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<GXRewriter>();

0 commit comments

Comments
 (0)