You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently we solved an issue in a plugin which prevented us from redirecting to substores with returnUrl after signing in, and I think this quick fix might be also of your and the general user base's interest.
The issue is coming from checking if the redirect URL is local with the built-in IUrlHelper.IsLocalUrl method, which treats absolute URLs as foreign. The problem with this approach is if substores are hosted under subdomains or different domain names, this method fails to recognize them. Consequently, the logic redirects to the main store's home page instead of the expected destination.
Please consider adding a custom URL check to nopCommerce to recognize such configurations. If you like the idea then I would recommend putting something like this in WebHelper:
publicasyncTask<bool>IsLocalUrlAsync(stringurl){IUrlHelperurlHelper=_urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);if(urlHelper.IsLocalUrl(url))returntrue;// Absolute URL, check if it belongs to a local storeIList<Store>stores=await_storeService.GetAllStoresAsync();foreach(Storestoreinstores){stringscheme=store.SslEnabled?Uri.UriSchemeHttps:Uri.UriSchemeHttp;// Alternatively expose StoreService.ParseHostValues and use that.string[]hosts=store.Hosts.Split(',');if(hosts.Any(host =>url.StartsWith($"{scheme}{Uri.SchemeDelimiter}{host}"))){returntrue;}}returnfalse;}
The WebHelper class can take an additional StoreService dependency. Then whenever a URL is checked with IsLocalUrl, like in SignInCustomerAsync, you can simply use this extended check instead.
The text was updated successfully, but these errors were encountered:
nopCommerce version: 4.70+
Recently we solved an issue in a plugin which prevented us from redirecting to substores with
returnUrl
after signing in, and I think this quick fix might be also of your and the general user base's interest.The issue is coming from checking if the redirect URL is local with the built-in
IUrlHelper.IsLocalUrl
method, which treats absolute URLs as foreign. The problem with this approach is if substores are hosted under subdomains or different domain names, this method fails to recognize them. Consequently, the logic redirects to the main store's home page instead of the expected destination.Please consider adding a custom URL check to nopCommerce to recognize such configurations. If you like the idea then I would recommend putting something like this in
WebHelper
:The
WebHelper
class can take an additionalStoreService
dependency. Then whenever a URL is checked withIsLocalUrl
, like inSignInCustomerAsync
, you can simply use this extended check instead.The text was updated successfully, but these errors were encountered: