URL issues -- Running BE behind a load balancer

Oct 2, 2009 at 4:52 PM

I'm having url issues when running BlogEngine.net on a server that sits behind a load balancer. The basic issues is the url www.whatever.com (which is set up on the server on, say, port 150) is getting rewritten to www.whatever.com:150 for certain urls (for instance, when you try to save a post or after you log in). Any ideas on how to force it to use the correct url? Thanks!

Oct 3, 2009 at 12:01 AM
Edited Oct 3, 2009 at 12:01 AM

One possible thing that could help, but might not help for the cases you described would be to change the AbsoluteWebRoot property in the Utils.cs file (in the BE core).  Currently, there's this line of code which picks up the port:

context.Items["absoluteurl"] = new Uri(context.Request.Url.GetLeftPart(UriPartial.Authority) + RelativeWebRoot);

Changing that (and re-compiling the BE core) to the following would exclude the port:

context.Items["absoluteurl"] = new Uri(context.Request.Url.GetLeftPart(UriPartial.Scheme) + context.Request.Url.Host + RelativeWebRoot);

However, the 2 examples you give (saving a post and logging in) I don't believe make use of AbsoluteWebRoot ... so this change probably wouldn't help for these 2 instances.

I'm sure there's a reason, but couldn't you switch to using port 80?  Even in a non-load balancing environment, using port 150 instead of 80 would probably present the same issue you're having.  I could be wrong, but this sounds like more of a port related problem than a load balancing problem.

Oct 3, 2009 at 3:42 PM
Edited Oct 3, 2009 at 3:46 PM

I believe that when you visiting a website using a url such as http://www.whatever.com is just an alias of http://www.whatever.com:80 and this is because 80 is the default port of http protocol that is widely used. Even your site needs a number 150 as a default http port, there is no http://www.whatever.com as an alias for http://www.whatever.com:150 , the browser needs to tell itself that the destination port is 150. So maybe this behaviour is not only caused by the server but also the browser behavior.

I believe the above thing which I said because I have tried some port numbers other than 80 for the default website of IIS on Windows 2003, and when I visiting http://www.mysite.com , I can't open the homepage until I explictly add the port number to the url.

Oct 5, 2009 at 7:33 PM

I essentially have a public-facing code branch that forms part of a larger website, and an admin site code branch. I've customized the public-facing code branch so that it uses an "override" URL if I specify it in the web.config. This works well enough for browsing the blog, but not so good for admin. So, for the admin site, I spent a few hours addressing each control and how it redirects. For instance, the login control can have a default url specified and I changed that the the absolute path to the site. The "Save Posts" button uses a web.config-specified url that I also use as the image url (in my case, images sit on the admin site -- admin.whatever.com, and the blog is served as part of another site: www.whatever.com/blog) in lieu of the RelativePath variable it was using. I've got all the essential stuff working now (logoff doesn't redirect to the corret page yet, but I'll worry about that one later).

Miller, the issue is that the load balancer reports the port to the server it's contacting. Say, for instance, you have a load balancer sitting in front of two web servers. You type www.whatever.com, which the load balancer will translate to a local ip address + a port number: or That port number gets picked up by all sorts of underlying processes and parroted back when the web servers serve up the page. So, if you view the source of the page and look at the links, you'll see stuff like "www.whatever.com:100" in front of all your links that are not specified as absolute.

Aug 27, 2012 at 11:45 PM
Edited Aug 27, 2012 at 11:56 PM

I am having similar problems trying to run BE on a Cloud-based hosting service which runs a load-balanced environment. Looking for help on their forum, I received what I think is good explanation of the problem. In the thread here (http://support.uhurusoftware.com/entries/21888211-error-running-blogengine-net-build), the good Mr. Dragos made the the following analysis :

...this problem occurs because BlogEngine.Net was not design to run behind a load balancer.
The load balacer is listeneing on port 80 and the web app on a non standard port in IIS, in your case 57234. When the app returns its uri, it adds the port it is being accessed by the load balancer....

You can see the problems in action at the BE instance running at (http://blogenginewssseb.uhurucloud.com/)

In his response, he also demonstrated how another open source .net blog platform handles this issue, referencing a bit of code at:


Could a similar implementation be done with BE, thereby eliminating problems on load balanced hosts?


(I see the last message in this discussion is a little old -- I hope I'll still be able to get some feedback. I'm considering starting a new thread....)