Port Number Added to Links

Topics: ASP.NET 2.0, Controls
Jul 9, 2008 at 3:07 PM
Edited Jul 9, 2008 at 3:14 PM
Hi guys:

Our web server environment sits behind load balancers and all sites use port mapping, load balanced or not.

Externally the address for the blog is:  


The load balancer is configured as:

    blog.company.com:80 mapped ---> web server:8048

The issue is the application appends a port number to all links within the site such as:

Port 8048 is not a valid external port for external access.  Since port mapping an extremely common method in load balanced environments, I suspect others have run into this issue as well. If anyone could provide some guidance, it would be greatly appreciated.
The desired end result is that port numbers are never appended to any of the links.

Jul 25, 2008 at 2:07 PM
I ran into the same problem and created a little function to get around this.

Try pasting the following code into your Util.cs file under blogengine.core.

public static Uri AbsoluteWebRootWithoutPort
                HttpContext context = HttpContext.Current;
                string protocol = context.Request.ServerVariables["SERVER_PORT_SECURE"];

                if (protocol == null || protocol == "0")
                    protocol = "http://";
                    protocol = "https://";

                string strUri = protocol + context.Request.ServerVariables["SERVER_NAME"].ToString() + RelativeWebRoot;

                return new Uri(strUri);

After that, you must change all of the calls to AbsoluteWebRoot and replace them with a call to your new function AbsoluteWebRootWithoutPort.

Hope that helps some.

Jul 30, 2008 at 6:52 PM
I noticed after creating the function above that I was still having some problems with the port number being appended to the urls.  After some research, we found that there is an entry in the web config that I was overlooking.  <httpRuntime enableVersionHeader="false" useFullyQualifiedRedirectUrl="false" maxRequestLength="16384" executionTimeout="50000" requestLengthDiskThreshold="16384"/> .  The useFullyQualifiedRedirectUrl attribute was set to true and was causing the port number to be appended upon redirect.
Aug 7, 2008 at 4:35 PM


We ran into the same problem and tried catwood's suggestion to modify the useFullyQualifiedRedirectUrl attribute in Web.config. It fixed the problem with the application appending a port number, however it broke both the comment and edit commands in postings. Did anyone else experience this issue? Thanks for any help.