Uri.EscapeDataString(Request.Url.AbsoluteUri) is wrong in different environment, What else should I use?
-
21-08-2019 - |
Question
I am generating a return url link so when the user hits the close button on this page they return to this ReturnUrl.
This works fine in dev environment, but in uat environment I have
Notice the extra 01 on the ReturnUrl parameter.
So to generate the ReturnUrl bit I'm currently using
Uri.EscapeDataString(Request.Url.AbsoluteUri)
As I dont have direct access to the uat environment I dont know what will definetly work until after a release cycle so if I can avoid getting it wrong the first time that would be helpful.
Looking at Request.Url in debug the possibilities I have
DnsSafeHost or Host
which could be used with
AbsolutePath or LocalPath or PathAndQuery
or I have
OriginalString
Or I maybe I could use the referer instead?
Solution
PathAndQuery gives you a relative path with querystring vars so you don't have to worry about the extra '01' on the domain. Just deal with relative paths.
Out of curiosity, is your uat environment load balanced? It appears that your app is confused as to which domain it's responding on. This could(possibly) happen if a request hits a balanced server directly versus the load balance point or the load balancer forwards requests to machine-specific domain?
I would request info from your network admin. If you describe what you're doing in great detail, especially that your app sometimes believes it's responding on app-uat-01, they might see the issue right away.