Question

I have the following code:

var redirectIp = string.Format("{0}{1}", Session["CurrentHost"], ip.PathAndQuery);
return new RedirectResult(redirectIp);

When I check the value of redirectIP it gives me:

redirectIp  "127.0.0.1:84/Administration/Accounts/ShowSummary?ds=0001"  string

However when I step through the code the browser opens and gives me the following:

http://127.0.0.1:84/Administration/Accounts/127.0.0.1:84/Administration/Accounts/ShowSummary?ds=0001

I am totally confused. Anyone have any idea what's happening?

Was it helpful?

Solution

That is how urls, http and browsers work. You forgot the protocol part, so the redirect actually does work as expected, given the url that you are redirecting to.

var redirectIp = string.Format("http://{0}{1}", Session["CurrentHost"], ip.PathAndQuery);
return new RedirectResult(redirectIp);

This will work better for now, but to be able to also cover https, you're better off storing the protocol part in a session variable along with the hostname.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top