From 896f531f4f6fc7f0e8dfcfc0d6433850233ee749 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 14 May 2020 19:25:51 -0400 Subject: [PATCH] fix broken action links after update to .NET Core 3.0 --- src/SMAPI.Web/Framework/Extensions.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SMAPI.Web/Framework/Extensions.cs b/src/SMAPI.Web/Framework/Extensions.cs index 96463233..ad7e645a 100644 --- a/src/SMAPI.Web/Framework/Extensions.cs +++ b/src/SMAPI.Web/Framework/Extensions.cs @@ -22,6 +22,7 @@ namespace StardewModdingAPI.Web.Framework /// The generated URL. public static string PlainAction(this IUrlHelper helper, [AspMvcAction] string action, [AspMvcController] string controller, object values = null, bool absoluteUrl = false) { + // get route values RouteValueDictionary valuesDict = new RouteValueDictionary(values); foreach (var value in helper.ActionContext.RouteData.Values) { @@ -29,13 +30,19 @@ namespace StardewModdingAPI.Web.Framework valuesDict[value.Key] = null; // explicitly remove it from the URL } + // get relative URL string url = helper.Action(action, controller, valuesDict); + if (url == null && action.EndsWith("Async")) + url = helper.Action(action[..^"Async".Length], controller, valuesDict); + + // get absolute URL if (absoluteUrl) { HttpRequest request = helper.ActionContext.HttpContext.Request; Uri baseUri = new Uri($"{request.Scheme}://{request.Host}"); url = new Uri(baseUri, url).ToString(); } + return url; }