Skip to content

Commit d714445

Browse files
Removed .aspx extension from ASP.NET Core web pages (#1050)
* Remove .aspx extension for ASP.NET Core web objects while maintaining support for executing legacy .aspx URLs. * Fix 404 not found for Webpanels in modules
1 parent 04be3b6 commit d714445

File tree

6 files changed

+45
-40
lines changed

6 files changed

+45
-40
lines changed

dotnet/src/dotnetcore/GxClasses.Web/Middleware/HandlerFactory.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async Task Invoke(HttpContext context)
6767
{
6868
context.Response.OnStarting(() =>
6969
{
70-
if (context.Response.StatusCode == (int)HttpStatusCode.OK && url.EndsWith(HttpHelper.ASPX) && string.IsNullOrEmpty(context.Response.ContentType))
70+
if (context.Response.StatusCode == (int)HttpStatusCode.OK && string.IsNullOrEmpty(context.Response.ContentType))
7171
{
7272
context.Response.ContentType = MediaTypesNames.TextHtml;
7373
//If no ContentType is specified, the default is text/HTML.
@@ -98,11 +98,6 @@ public async Task Invoke(HttpContext context)
9898
await Task.FromException(ex);
9999
}
100100
}
101-
public static bool IsAspxHandler(string path, string basePath)
102-
{
103-
string name = ObjectUrl(path, basePath);
104-
return name.EndsWith(HttpHelper.ASPX, StringComparison.OrdinalIgnoreCase) || _aspxObjects.ContainsKey(name);
105-
}
106101
private static string ObjectUrl(string requestPath, string basePath)
107102
{
108103
string lastSegment = requestPath;
@@ -120,10 +115,17 @@ private static string ObjectUrl(string requestPath, string basePath)
120115
}
121116
private static string CleanUploadUrlSuffix(string url)
122117
{
118+
#if NETCORE
119+
if (url.EndsWith($"{HttpHelper.GXOBJECT}", StringComparison.OrdinalIgnoreCase))
120+
{
121+
return url.Substring(0, url.Length - (HttpHelper.GXOBJECT.Length));
122+
}
123+
#else
123124
if (url.EndsWith($"{HttpHelper.ASPX}{HttpHelper.GXOBJECT}", StringComparison.OrdinalIgnoreCase))
124125
{
125126
return url.Substring(0, url.Length - (HttpHelper.GXOBJECT.Length));
126127
}
128+
#endif
127129
else
128130
return url;
129131
}
@@ -132,9 +134,12 @@ public IHttpHandler GetHandler(HttpContext context, string requestType, string u
132134
GXLogging.Debug(log, "GetHandler url:", url);
133135

134136
IHttpHandler handlerToReturn =null;
135-
136-
int idx = url.LastIndexOf('.');
137+
int idx = -1;
137138
string cname0;
139+
if (url.EndsWith(HttpHelper.ASPX, StringComparison.OrdinalIgnoreCase))
140+
{
141+
idx = url.LastIndexOf('.');
142+
}
138143
if (idx >= 0)
139144
cname0 = url.Substring(0, url.LastIndexOf('.')).ToLower();
140145
else

dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,8 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
578578
Config.ScriptPath = string.IsNullOrEmpty(basePath) ? "/" : basePath;
579579
app.MapWebSocketManager(basePath);
580580

581-
app.MapWhen(
582-
context => IsAspx(context, basePath),
583-
appBranch =>
584-
{
585-
appBranch.UseGXHandlerFactory(basePath);
586-
});
581+
app.UseGXHandlerFactory(basePath);
582+
587583
app.Run(async context =>
588584
{
589585
await Task.FromException(new PageNotFoundException(context.Request.Path.Value));
@@ -638,11 +634,6 @@ private void AddRewrite(IApplicationBuilder app, string rewriteFile, string base
638634
app.UseRewriter(options);
639635
}
640636
}
641-
642-
bool IsAspx(HttpContext context, string basePath)
643-
{
644-
return HandlerFactory.IsAspxHandler(context.Request.Path.Value, basePath);
645-
}
646637
}
647638
public class CustomExceptionHandlerMiddleware
648639
{

dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,23 @@ public class HttpHelper
171171
static readonly IGXLogger log = GXLoggerFactory.GetLogger<HttpHelper>();
172172

173173
internal static Dictionary<string, string> GAMServices = new Dictionary<string, string>(){
174-
{"oauth/access_token","gxoauthaccesstoken.aspx"},
175-
{"oauth/logout","gxoauthlogout.aspx"},
176-
{"oauth/userinfo","gxoauthuserinfo.aspx"},
177-
{"oauth/gam/signin","agamextauthinput.aspx"},
178-
{"oauth/gam/callback","agamextauthinput.aspx"},
179-
{"oauth/gam/access_token","agamoauth20getaccesstoken.aspx"},
180-
{"oauth/gam/userinfo","agamoauth20getuserinfo.aspx"},
181-
{"oauth/gam/signout","agamextauthinput.aspx"},
174+
{"oauth/access_token","gxoauthaccesstoken"},
175+
{"oauth/logout","gxoauthlogout"},
176+
{"oauth/userinfo","gxoauthuserinfo"},
177+
{"oauth/gam/signin","agamextauthinput"},
178+
{"oauth/gam/callback","agamextauthinput"},
179+
{"oauth/gam/access_token","agamoauth20getaccesstoken"},
180+
{"oauth/gam/userinfo","agamoauth20getuserinfo"},
181+
{"oauth/gam/signout","agamextauthinput"},
182182
{"saml/gam/signin","Saml2/SignIn"},
183-
{"saml/gam/callback","gamexternalauthenticationinputsaml20_ws.aspx"},
183+
{"saml/gam/callback","gamexternalauthenticationinputsaml20_ws"},
184184
{"saml/gam/signout","Saml2/Logout"},
185-
{"oauth/requesttokenservice","agamstsauthappgetaccesstoken.aspx"},
186-
{"oauth/queryaccesstoken","agamstsauthappvalidaccesstoken.aspx"},
187-
{"oauth/gam/v2.0/access_token","agamoauth20getaccesstoken_v20.aspx"},
188-
{"oauth/gam/v2.0/userinfo","agamoauth20getuserinfo_v20.aspx"},
189-
{"oauth/gam/v2.0/requesttokenanduserinfo","agamssorestrequesttokenanduserinfo_v20.aspx"}};
190-
internal static HashSet<string> GamServicesInternalName = new HashSet<string>(GAMServices.Values.Select(value => value.Replace(ASPX, string.Empty)));
185+
{"oauth/requesttokenservice","agamstsauthappgetaccesstoken"},
186+
{"oauth/queryaccesstoken","agamstsauthappvalidaccesstoken"},
187+
{"oauth/gam/v2.0/access_token","agamoauth20getaccesstoken_v20"},
188+
{"oauth/gam/v2.0/userinfo","agamoauth20getuserinfo_v20"},
189+
{"oauth/gam/v2.0/requesttokenanduserinfo","agamssorestrequesttokenanduserinfo_v20"}};
190+
internal static HashSet<string> GamServicesInternalName = new HashSet<string>(GAMServices.Values);
191191
internal const string QUERYVIEWER_NAMESPACE = "QueryViewer.Services";
192192
internal const string GXFLOW_NSPACE = "GXflow.Programs";
193193
internal const string GAM_NSPACE = "GeneXus.Security.API";

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ public bool IsSameComponent(string oldName, string newName)
12001200
{
12011201
return true;
12021202
}
1203-
else if (newName.Trim().ToLower().StartsWith(oldName.Trim().ToLower() + ".aspx"))
1203+
else if (newName.Trim().ToLower().StartsWith(oldName.Trim().ToLower() + HttpHelper.ASPX))
12041204
{
12051205

12061206
return true;
@@ -2315,7 +2315,7 @@ private string GetGAMLoginWebObject()
23152315
{
23162316
string[] loginObjParts = loginObject.Split(',');
23172317
if (loginObjParts.Length > 0)
2318-
loginObject = loginObjParts[0] + ".aspx";
2318+
loginObject = AddExtension(loginObjParts[0]);
23192319
}
23202320
if (IsUploadRequest(this.localHttpContext))
23212321
return formatLink($"{context.GetScriptPath()}{loginObject}");
@@ -2329,13 +2329,22 @@ private string GetGAMNotAuthorizedWebObject()
23292329
{
23302330
string[] loginObjParts = loginObject.Split(',');
23312331
if (loginObjParts.Length > 0)
2332-
loginObject = loginObjParts[0] + ".aspx";
2332+
loginObject = AddExtension(loginObjParts[0]);
23332333
}
23342334
if (IsUploadRequest(this.localHttpContext))
23352335
return formatLink($"{context.GetScriptPath()}{loginObject}");
23362336
else
23372337
return formatLink(loginObject);
23382338
}
2339+
private string AddExtension(string objectName)
2340+
{
2341+
#if NETCORE
2342+
return objectName;
2343+
#else
2344+
return $"{objectName}{HttpHelper.ASPX}";
2345+
#endif
2346+
}
2347+
23392348
private void SendHeaders()
23402349
{
23412350
sendCacheHeaders();
@@ -2889,7 +2898,7 @@ public void CallWebObject(string url)
28892898
}
28902899
private string RemoveExtensionFromUrlPath(string urlPath)
28912900
{
2892-
if (urlPath.EndsWith(".aspx"))
2901+
if (urlPath.EndsWith(HttpHelper.ASPX))
28932902
return urlPath.Substring(0, urlPath.Length - 5);
28942903
return urlPath;
28952904
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void context_EndRequest(object sender, EventArgs e)
297297
if (context.Request != null && context.Request.RequestType == "GET" && context.Response.StatusCode == 200)
298298
{
299299
string filePath = context.Request.FilePath;
300-
if (filePath.IndexOf(".svc") < 0 && filePath.IndexOf(".aspx") < 0 && isCacheableMimeType(filePath))
300+
if (filePath.IndexOf(".svc") < 0 && filePath.IndexOf(HttpHelper.ASPX) < 0 && isCacheableMimeType(filePath))
301301
{
302302
context.Response.Cache.SetCacheability(HttpCacheability.Public);
303303
context.Response.Cache.SetMaxAge(new TimeSpan(GXStaticCacheModule.cacheExpirationHours, 0, 0));

dotnet/src/dotnetframework/GxClasses/Model/GXBaseObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private string GetCallTargetFromUrl(string urlString)
294294

295295
private string RemoveExtensionFromUrlPath(string urlPath)
296296
{
297-
if (urlPath.EndsWith(".aspx"))
297+
if (urlPath.EndsWith(HttpHelper.ASPX))
298298
return urlPath.Substring(0, urlPath.Length - 5);
299299
return urlPath;
300300
}

0 commit comments

Comments
 (0)