Indeed, the Forums do not support attachments, sorry for this. Here is one of the implementation of HttpModule.
using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Security.Principal;
using System.Data.OleDb;
using Telerik.ContentManagement;
using Telerik.ContentManagement.UserManagement;
using Telerik.ServerUtils;
namespace TelerikGenericApplication
{
/// <summary>
/// Represents an HttpModule responsible for URL rewriting and user authorization.
/// </summary>
public class CustomTelerikHttpModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.AuthenticateRequest += new EventHandler(this.Application_AuthenticateRequest);
application.Error += (new EventHandler(this.Application_Error));
}
// Rewrites both global page ID and friendly page names URLs
protected virtual void RewriteUrl(bool isPublic)
{
HttpContext context = HttpContext.Current;
string path = context.Request.Path;
if (path.EndsWith("Default.aspx"))
{
return;
}
if (path.EndsWith("Login.aspx"))
{
return;
}
if (!path.EndsWith(".aspx"))
{
return;
}
path = context.Request.RawUrl.Replace(applicationPath, "");
string pageGuid = string.Empty;
string pageName = path.Substring(0, path.LastIndexOf("."));
try
{
Guid guid = new Guid(pageName);
pageGuid = guid.ToString();
}
catch
{
// the names are separated by '_'
string[] names = pageName.Split('_');
DataTable pagesTable;
if (isPublic)
{
pagesTable = TelerikCmsContext.Current.CmsManager.GetPublishedPages();
}
else
{
pagesTable = TelerikCmsContext.Current.CmsManager.GetPages();
}
DataRow[] rows = pagesTable.Select("ParentPageId IS NULL");
DataRow resultRow = rows[0];
for ( int i = 0; i < names.Length; i++ )
{
resultRow = GetResultRow(resultRow, names[i]);
if (resultRow == null)
{
return;
}
}
pageGuid = (string)resultRow["PageGuid"];
}
if (pageGuid.Length == 36)
{
string queryString = string.Empty;
path = context.Request.RawUrl;
int index = path.LastIndexOf("?");
if (index > 0)
{
queryString = "&" + path.Substring(index + 1);
}
HttpContext.Current.Items["TelerikCmsVirtualUrl"] = path;
context.RewritePath("~/Default.aspx?Page=" + pageGuid + queryString);
}
}
private void Application_Error(object source, EventArgs args)
{
HttpApplication application = (HttpApplication) source;
Exception last = application.Server.GetLastError();
if (last is SecurityException)
{
FormsAuthentication.SignOut();
application.Context.Response.Redirect(application.Context.Request.RawUrl, true);
}
else
{
if (last is HttpUnhandledException)
{
last = ((HttpUnhandledException) last).InnerException;
}
if ((last is OleDbException) || (last is InvalidLicenseFileException))
{
string applicationPath = ServerInfo.ApplicationPath;
if (applicationPath != "/")
{
applicationPath += "/";
}
applicationPath += ServerInfo.AppSettings["appName"];
if (!applicationPath.EndsWith("/"))
{
applicationPath += "/";
}
if ((last is OleDbException) &&
(CannotWriteToDbFile(last as OleDbException)))
{
application.Context.Response.Redirect(applicationPath + "PermissionsError.aspx", true);
}
else if (last is InvalidLicenseFileException)
{
application.Context.Response.Redirect(applicationPath + "LicenseError.aspx", true);
}
}
}
}
private bool CannotWriteToDbFile(OleDbException dbError)
{
if (dbError == null)
return false;
const string COULD_NOT_DELETE_FROM_SPECIFIED_TABLES = "3086";
const string OPERATION_MUST_USE_AN_UPDATEABLE_QUERY = "3073";
foreach (OleDbError realError in dbError.Errors)
{
if (realError.SQLState == COULD_NOT_DELETE_FROM_SPECIFIED_TABLES
||
realError.SQLState == OPERATION_MUST_USE_AN_UPDATEABLE_QUERY)
return true;
}
return false;
}
private void Application_AuthenticateRequest(object source, EventArgs e)
{
bool isPublic = true;
HttpApplication application = (HttpApplication) source;
HttpContext context = application.Context;
bool authenticated = context.Request.IsAuthenticated;
IPrincipal requestPrincipal = null;
if (authenticated && (context.User.Identity is FormsIdentity))
{
isPublic = false;
IPrincipal formsPrincipal = context.User;
string[] userData = ((FormsIdentity) formsPrincipal.Identity).Ticket.UserData.Split(';');
string[] roles = userData[0].Split(',');
int userId = int.Parse(formsPrincipal.Identity.Name);
UserPrincipal newPrincipal = CreatePrincipal(userId, roles, userData, context);
try
{
string connectionString = newPrincipal.ConnectionString;
object dbMode = newPrincipal.DbMode;
if (connectionString == "" || dbMode == null)
throw new ArgumentException("BadConfiguration");
requestPrincipal = newPrincipal;
}
catch (ArgumentException)
{
}
}
if (requestPrincipal == null)
{
requestPrincipal = new AnonymousPrincipal();
}
context.User = requestPrincipal;
// Calling rewrite method
RewriteUrl(isPublic);
}
protected virtual UserPrincipal CreatePrincipal(int userId, string[] roles, string[] userData, HttpContext context)
{
UserPrincipal newPrincipal = new CachingUserPrincipal(userId);
newPrincipal.RoleNames = roles;
if (userData.Length == 2)
{
string realName = ServerInfo.AppSettings["appName"];
if (!realName.EndsWith("/"))
{
realName += "/";
}
newPrincipal.AppName = userData[1];
if ((newPrincipal.AppName != realName) && (realName != "/"))
{
FormsAuthentication.SignOut();
context.Response.Redirect(context.Request.RawUrl, true);
}
}
else
{
newPrincipal.AppName = null;
}
return newPrincipal;
}
public void Dispose()
{
}
private DataRow GetResultRow(DataRow parentRow, string pageName)
{
foreach ( DataRow row in parentRow.GetChildRows(TelerikCmsContext.Current.CmsManager.ParentRelationName) )
{
if (pageName.Equals((string)row["PageName"]))
{
return row;
}
}
return null;
}
private string applicationPath
{
get
{
string appPath = HttpContext.Current.Request.ApplicationPath;
if (appPath != "/")
appPath += "/";
appPath += System.Configuration.ConfigurationSettings.AppSettings["appName"];
if (!appPath.EndsWith("/"))
appPath += "/";
return appPath;
}
}
}
}
Regards,
the telerik team