Update for the MCMS SSL Http Module (last updated: July 3rd, 2004)
I received some feedback about my CmsSslHttpModule. Some tried to use this module together with my CmsNiceUrlHttpModule. The result: when the CmsSslHttpModule switches between http and https the URLs did not change to the friendly URLs.
I analyzed the problem and found a workaround. The code below is an adjusted version of the CmsSslHttpModule which addresses this.
This code uses the NRORIGINALURL query string parameter to identify the friendly URL. There is a bug in MCMS 2002 SP1a (not sure if it also is in SP1 but might be) which removes all custom query strings from the NRORIGINALURL. So if your solution works with query string parameters to your postings, then you have to install the following hotfix which can be requested free of charge from Microsoft: 836895
using System;
using System.Web;
using Microsoft.ContentManagement.Publishing;
namespace StefanG.HttpModules
{
public class CmsSslHttpModule : IHttpModule
{
public void Init(HttpApplication httpApp)
{
httpApp.PreRequestHandlerExecute += new EventHandler(this.OnPreRequestHandlerExecute);
}
public void Dispose()
{
// nothing to do...
}
public void OnPreRequestHandlerExecute(object o, EventArgs e)
{
HttpApplication httpApp = (HttpApplication) o;
HttpContext ctx = HttpContext.Current;
CmsHttpContext cmsContext = null;
// try-catch to prevent access denied exception during forms login.
try
{
cmsContext = CmsHttpContext.Current;
}
catch
{
// nothing to do...
}
if (cmsContext != null)
{
if (cmsContext.Channel != null)
{
bool RequireSSL = false;
if (cmsContext.Channel.CustomProperties["RequireSSL"] != null)
{
RequireSSL = (cmsContext.Channel.CustomProperties["RequireSSL"].Value).ToLower() == "yes";
}
string Url = "";
string UglyUrl = ctx.Request.Url.PathAndQuery;
if (cmsContext.Mode == PublishingMode.Published)
{
if (ctx.Request.QueryString["NRORIGINALURL"] != null)
{
Url = ctx.Request.QueryString["NRORIGINALURL"];
}
}
if (Url != "")
Url = ctx.Request.Url.Host+Url;
else
Url = ctx.Request.Url.Host+UglyUrl;
if (RequireSSL & !ctx.Request.IsSecureConnection)
ctx.Response.Redirect("https://"+Url);
if (!RequireSSL & ctx.Request.IsSecureConnection)
ctx.Response.Redirect("http://"+Url);
}
}
}
}
}