0

I'm trying redirect to url using Response.Redirect(url) in C#.

For example, Actually I'm browsing in http://www.mysite.abc:8095/app/page.aspx

And In a Page_Load I have a Response.Redirect ("../ptd/page2.aspx")

After this event, the browser has http://www.mysite.abc/ptd/page2.aspx (without the port)

do someone know about this?

Manuel
  • 1
  • 1
  • As far as I know, if you use Response.Redirect it will not modify the port number in the url. Do you enabled any url rewrite or httpredirect in your web.config? Is this issue only happened when you hosted the application in the IIS? – Brando Zhang Nov 25 '19 at 03:00

1 Answers1

0

Port numbers are part of the URL's host segment. When you use relative urls, you use the same host information. The only way to change the host (including port) is to specify an entirely new host, which means means you must use an absolute URL.

You can do this in JavaScript by getting the current URL host info:

var full = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');

From Shef's answer

The other option is though your c# application's configuration, by specifying a "base url" at deploy time and using that to construct the new url before delivering the HTML to the client.

gunr2171
  • 16,104
  • 25
  • 61
  • 88