Asked by:
hostname disappears from URL

Question
-
User-459928879 posted
Hey everyone,
I've inherited some ASP.NET code for a website that manages user accounts for our products and I've been tasked with fixing a bug that has been plaguing this codebase.
It seems to happen completely at random, but sometimes when the code wants to redirect the user to a different page, the entire hostname segment of the URL gets removed.
See this image:
For some more context I'll describe the use-case: the user goes to https://website.com/en/users/add to create a new user account, once the form has been posted and the ASP.NET code should redirect the user back to the index page.
But the URL in the browser changes to that seen in the image.This seems to happen very randomly, sometimes it works fine other times it does not.
Frustratingly, it seems to work fine with I run the code locally or in our test environment.Does anyone have any tips on what could be causing this and how I can debug this?
Monday, October 26, 2020 2:39 PM
All replies
-
User475983607 posted
the entire hostname segment of the URL gets removed.I'm guessing the redirect URL is dynamically generated. There's a bug in the code that generates the URL. Maybe bad data.
Monday, October 26, 2020 4:34 PM -
User-459928879 posted
I'm guessing the redirect URL is dynamically generated.It's not, as far as I can tell.
The controller which the data is posted to simply calls the MVC "Redirect" method to send the user to the Index action.
There are a lot of action filters in place, some of which change the destination for localization purposes. I've been looking into that code but my findings there have been inconclusive.
Someone remarked that the reason it does this might be because the redirect sends me to "//"users/index.
the format of our url is /[locale]/[controller]/[action] so there seems to be something there.
That, and I remember reading that incorrect RoutingDictionaries might cause this too.Is there any correlation there?
Monday, October 26, 2020 5:03 PM -
User475983607 posted
We cannot see the code. The best we can do is illustrate how to cause this issue.
public class BasicFormsController : Controller { // GET: BasicForms [HttpGet] public ActionResult Index() { string url = "https://BasciForms/Index"; return Redirect(url); }
public class BasicFormsController : Controller { // GET: BasicForms [HttpGet] public ActionResult Index() { string url = "//BasciForms/Index"; return Redirect(url); }
<div> <a href="//BasicForms/Index">Index</a> </div> <div> <a href="https://BasicForms/Index">Index</a> </div>
I'm guessing the redirect URL is dynamically generated.
It's not, as far as I can tell.
I assume the redirect URL is dynamically generated otherwise finding "http" or "//" in the source code is very simple and the code would always behave the same way. Being the issue is random points to a logical bug.
Monday, October 26, 2020 5:38 PM -
User1535942433 posted
Hi Tververs89,
As far as I think,you could try RawUrl instead to retrieve exact URL typed in browser.
More details,you could refer to below article:
Best regards,
Yijing Sun
Tuesday, October 27, 2020 8:25 AM