Suggested modification to ease using BE under another portal

Topics: Business Logic Layer
Nov 8, 2010 at 2:11 PM

Hello, 

Moving BlogEngine to a subfolder and using it under a web site doesn't work from scratch, and I suggest some modifications to the source code which, without changing the default behaviours could ease the sub folder move.
This is valid for vertsion 1.6.2.33

First some changes in source c# code :
C:\Blogs\blogengine\BlogEngine\DotNetSlave.BusinessLogic\Utils.cs(362): 
// CS ADNT var fileEntries = Directory.GetFiles(HostingEnvironment.MapPath("~/" + pathFromRoot))
var fileEntries = Directory.GetFiles(HostingEnvironment.MapPath("/" + pathFromRoot))

C:\Blogs\blogengine\BlogEngine\DotNetSlave.BusinessLogic\Web\Controls\BlogBasePage.cs(357): 
// CS ADNT Utils.AddFolderJavaScripts(this, "Scripts", true);
Utils.AddFolderJavaScripts(this, string.Format("{0}Scripts", Utils.RelativeWebRoot), true);
//CS ADNT Utils.AddFolderJavaScripts(this, string.Format("themes/{0}", this.theme), true);
Utils.AddFolderJavaScripts(this, string.Format("{0}themes/{1}", Utils.RelativeWebRoot, this.theme), true);

C:\Blogs\blogengine\BlogEngine\DotNetSlave.BusinessLogic\Web\HttpHandlers\JavaScriptHandler.cs(165): 
// CS ADNT var path = HttpContext.Current.Server.MapPath(file);
var path = HttpContext.Current.Server.MapPath("/"+file);

C:\Blogs\blogengine\BlogEngine\DotNetSlave.BusinessLogic\Web\HttpModules\UrlRewrite.cs(225): 
if ( Utils.IsMono ) // CS ADNT added to say compatible with another url rewritter, we do not need to change the default url
context.RewritePath(url.Replace("Default.aspx", "default.aspx")); // fixes a casing oddity on Mono

C:\Blogs\blogengine\BlogEngine\BlogEngine.NET\Account\Account.master.cs(45): 
// CS ADNT Utils.AddFolderJavaScripts(this.Page, "Scripts", true);
Utils.AddFolderJavaScripts(this.Page,string.Format("{0}Scripts", Utils.RelativeWebRoot), true);

C:\Blogs\blogengine\BlogEngine\BlogEngine.NET\MasterPages\admin.master.cs(111): 
// CS ADNT Utils.AddFolderJavaScripts(this.Page, "Scripts", false);
Utils.AddFolderJavaScripts(this.Page,string.Format("{0}Scripts", Utils.RelativeWebRoot), false);

C:\Blogs\blogengine\BlogEngine\BlogEngine.NET\MasterPages\admin1.master.cs(111): 
// CS ADNT Utils.AddFolderJavaScripts(this.Page, "Scripts", false);
Utils.AddFolderJavaScripts(this.Page,string.Format("{0}Scripts", Utils.RelativeWebRoot), false);

The we need some change in master pages

I suggest to create a new base folder nammed \MasterPages
and to move the from \admin to \MatserPages
Admi.master
Admin1.master
These pages must also be change to find the menu.ascx and the linked css
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="admin.master.cs" Inherits="Admin.AdminMasterPage" %>
<%@ Register Src="~/admin/menu.ascx" TagName="menu" TagPrefix="uc1" %>
<%@ Import Namespace="BlogEngine.Core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="height: 100%;">
<head id="Head1" runat="server">
<title>BlogEngine.NET Admin</title>
<link rel="stylesheet" href="~/admin/style.css" type="text/css" />
<link rel="stylesheet" href="~/admin/colorbox.css" type="text/css" />
<link rel="stylesheet" href="~/admin/tipsy.css" type="text/css" /> // Note here that this css does not exists in 1.6.2.33 ?????
<link rel="shortcut icon" href="~/pics/blogengine.ico" type="image/x-icon" />
</head>

The modify each aspx page using the admin masterpages
Replace « ~/admin/admin.master » by « ~/MsterPages/admin.master » (idem pour admin1.master)

Next in each aspx and ascx, replace absolute paths containing « ~/ » by corresponding relatives paths

as in src=«~/main/module.ascx » change for src= » »../module.ascx » 

take the opportunity to change codefile and inherit which contains absolute paths, as the associated cs file is in same folder there are no reasons to include a path

with these modifications, the normal install still works normally.
If you need to move to a subfolder you only need to change the master pages and replace the '~/main' path with '~/YourFolder/main' (change also config.sys as recommended by early install doc.


I hope this will be included in the next version, having not time to do all the path to update the scv.

Best regards
CS

CSADNT wrote Fri at 5:40 PM
Ok, I have done more work on this.
It appear that I don't have to move anything else that pics ... but some code has to be changed to fully and transparently adapt working in a subfolder or not.
Especially there should be an Init Method in Util which could be called from the externaml portal in its own Application_Start.
I will post something more detailled ASAP but my version is 1.6.2.11 and I will move to 1.6.2.33 before commenting.

CS