This project is read-only.

Recommendation Link URL Problem

Feb 27, 2010 at 4:54 AM
Edited Feb 27, 2010 at 5:16 AM

I have a problem with the recommendation link URL. This is what is inserted into an email message when you click the Email link at the end of each post. It is using the internal IP address of the server hosting the blog instead of the domain name exposed by the proxy server. It puts in instead of How do I fix that?

Updated 9:08: Actually, I see it is incorrect in all links in the post. I had a look at postview.ascx, but I'm not sure how to fix it there.

Feb 27, 2010 at 9:10 AM

It depends on what code you have in your PostView.ascx.  Different themes may be using different code.

The Indigo theme that ships with BE has:

<a rel="nofollow" href="mailto:?subject=<%=Server.UrlEncode(Post.Title) %>&amp;body=Thought you might like this: <%=Post.AbsoluteLink.ToString() %>">E-mail</a>

In this case, the URL to the post is coming from Post.AbsoluteLink.  AbsoluteLink is going to be using the same domain name that is used throughout BE.  If the email link in your PostView.ascx is using AbsoluteLink, this would mean that the internal IP address is most likely being used throughout your entire blog -- not just in this particular link.

What do you have in your PostView.ascx?  And do you not see other links in the site that also have the internal IP address?

Feb 27, 2010 at 4:08 PM

Yes, the internal IP address appears in all links in posts. How do I change that globally for the site?

I'm using the Indigo theme. It has the following postview.ascx code:

<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="false" Inherits="BlogEngine.Core.Web.Controls.PostViewBase" %>

<div id="post<%=Index %>">
    <h1><a href="<%=Post.RelativeLink %>"><%=Server.HtmlEncode(Post.Title) %></a></h1>
    <div><img id="Img1" src="~/themes/indigo/img/timeicon.gif" runat="server" alt="clock" /> <%=Post.DateCreated.ToString("MMMM d, yyyy HH:mm")%> by <img id="Img2" src="~/themes/indigo/img/author.gif" runat="server" alt="author" /> <a href="<%=VirtualPathUtility.ToAbsolute("~/") + "author/" + Post.Author %>.aspx"><%=Post.AuthorProfile != null ? Post.AuthorProfile.DisplayName : Post.Author%></a></div>
    <div><asp:PlaceHolder ID="BodyContent" runat="server" /></div>
    <%=Rating %>
    <br />
        Tags: <%=TagLinks(", ") %><br />
        Categories: <%=CategoryLinks(" | ") %><br />
        Actions: <%=AdminLinks %>
        <a rel="nofollow" href="mailto:?subject=<%=Server.UrlEncode(Post.Title) %>&amp;body=Thought you might like this: <%=Post.AbsoluteLink.ToString() %>">E-mail</a> |
        <a rel="nofollow" href="<%=Server.UrlEncode(Post.AbsoluteLink.ToString()) %>&amp;title=<%=Server.UrlEncode(Post.Title) %>">Kick it!</a> |
        <a href="<%=Post.PermaLink %>" rel="bookmark">Permalink</a> |
        <a rel="nofollow" href="<%=Post.RelativeLink %>#comment">
             <img id="Img4" runat="server" alt="comment" src="~/themes/indigo/img/comments.gif" /><%=Resources.labels.comments %> (<%=Post.ApprovedComments.Count %>)</a>
        <a rel="nofollow" href="<%=CommentFeed %>"><asp:Image ID="Image1" runat="Server" ImageUrl="~/pics/rssButton.gif" AlternateText="RSS comment feed" style="margin-right:3px" />Comment RSS</a>
    <br />

Feb 27, 2010 at 7:30 PM

I guess because of some type of router setup, proxy or URL rewrite schema, the blog is seeing the incoming URL as the internal IP address -- rather than the URL you see in address bar.

The simplest solution is to modify the BE core.  In there, there's a file names Utils.cs.  Within that is a property named "AbsoluteWebRoot".  This is the piece of code that is returning the first part of the URL.  You could hard code your real domain name in there.  If you did that, the new version of AbsoluteWebRoot would look like:

public static Uri AbsoluteWebRoot
        return new Uri("");

.... and substitute with your domain name.  After making this change, it would be necessary to recompile the BE core to produce a new BlogEngine.Core.dll file that would go into your BIN directory (overwriting the old one).

Feb 28, 2010 at 1:57 AM

Well, this is turning out to be more convoluted than I expected. I decided that if I was going to be mucking about in the code, I'd just as well get the latest version. Mistake.

Upgrading from to 1.6 was not straightforward, and ultimately I simply reinstalled. I revised the AbsoluteWebURI method, although the code was different from what I expected. I revised it as follows:

		public static Uri AbsoluteWebRoot
                                     return new Uri("");
                                     //if (_AbsoluteWebRoot == null)
				//HttpContext context = HttpContext.Current;
				//if (context == null)
				//	throw new System.Net.WebException("The current HttpContext is null");

				//if (context.Items["absoluteurl"] == null)
				//	context.Items["absoluteurl"] = new Uri(""); <-- in this contex, no worky

				//return context.Items["absoluteurl"] as Uri;
				//_AbsoluteWebRoot = new Uri(context.Request.Url.GetLeftPart(UriPartial.Authority) + RelativeWebRoot);// new Uri(context.Request.Url.Scheme + "://" + context.Request.Url.Authority + RelativeWebRoot);
				//return _AbsoluteWebRoot;

getting rid of all the checks, etc. and just blasting the URL in. When I rebuild the Visual Studio project, and drop the newly created .DLL in, it seems to work.

Now the absolute URL appears in the email message body. When I create a post, it uses that URL properly (apparently), and it uses the internal URL for comments, etc.

In reinstalling, however, I've somehow gone awry, because when I try to take any action in the right widget bar (using the Indigo theme) after logging in -- for instance, in About the Author, Edit -- nothing whatsoever happens, except that the Status Bar in the browser window  displays "Error on page." What might be the fix here?

Feb 28, 2010 at 2:37 AM

The "error on page" message is a JavaScript error.  If you have Firefox available, then pull up the blog in that, and check the Error Console (Tools -> Error Console).  It will usually give more detailed information on the error, compared to what Internet Explorer gives.

Feb 28, 2010 at 3:07 AM

Yes, I know it's Javascript error.

Actually IE 8 has a Developer Tools window (on the Tools menu or press F12), that has several views into the live page, and allows you to run a debugger against the live page.

When I click Start Debugging on the Tools Window, and click Edit on the blog window, the debugger breaks on the method being called, flags Blogengine.widgetAdmin.editWidget, and says that "Blogengine is undefined."

So I guess when I reinstalled, somehow I didn't get the configuration right in IIS, and it doesn't know about the application. Maybe because V. 1.6 installs under "BlogEngine.Web" and I used that. More monkeying around, looks like.

Feb 28, 2010 at 3:13 AM

I'm not sure if that's a typo, or the actual error message ... but a JS namespace for BE does exist, however it's BlogEngine -- not Blogengine (the casing is different).

When logged into the blog, the widget.js file in the admin folder should get loaded.  This contains the "BlogEngine.widgetAdmin" object.

Feb 28, 2010 at 6:10 AM


Feb 28, 2010 at 9:10 AM

Ok.  I also realized that BlogEngine.widgetAdmin is new in BE 1.6.  It wasn't there in BE 1.5.  So if you're still working on this, it sounds like (as you mentioned), you still have some BE 1.6 files in your blog.

Feb 28, 2010 at 5:30 PM

You write that it sounds like I "still have some BE 1.6 files in your blog". I think you meant to write that I still have some BE 1.5 files in my blog. I don't see how that can be because this is an entirely new installation of BE 1.6. Not an update/upgrade. (Update didn't work.)

I think IIS is misconfigured somehow. Not sure how that can be, because it does the right thing with the hard-coded URL, but not with the edit function. I would expect an all or none situation.

Anyway, still poking around.

Feb 28, 2010 at 8:25 PM

OK, I found the error. I assumed -- incorrectly, as it turns out -- that I could download the zipped-up distribution marked (Web) for BE 1.6, unzip it into the web location and all would be good.

Only partly true: That distribution apparently doesn't include any .js files. (At least that's what search for *.js in all the directories revealed.) It was no wonder that I couldn't edit the widgets with methods in Javascript: There was no Javascript.

When I take the source code distribution that I laltered to deal with the URL issue, and publish it to the desired location in IIS, it all suddenly works.

That does, however, seem confusing to me. Maybe there's something I'm not understanding about the distribution labeled (Web).

Feb 28, 2010 at 8:31 PM

Arrrgh! Except that now I can't edit things unless I do it locally. If I log in from the Internet, the Move/Edit/X links don't even appear.

Feb 28, 2010 at 11:42 PM

Ooops. The last bit is pilot error. In the last of several reinstalls of BE 1.6, I forgot to make myself an administrator, and must not have tried editing as myself locally, either.