简体   繁体   中英

Redirect to Url with port - IIS

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM