Sample HttpModule for CRM 2013 on premise.

Suppose we have to redirect user belonging to a specific group to some specific page, while they try to access CRM 2013.

For this we can implement an HttpModule

Sample code

public class Class1 : IHttpModule
public void Dispose()

public delegate void MyEventHandler(Object s, EventArgs e);
private MyEventHandler _eventHandler = null;

public event MyEventHandler MyEvent
add { _eventHandler += value; }
remove { _eventHandler -= value; }
public void Init(HttpApplication context)
context.AuthenticateRequest += new EventHandler(ContextOnAuthenticateRequest);

private void ContextOnAuthenticateRequest(object sender, EventArgs eventArgs)
HttpApplication app = sender as HttpApplication;
HttpContext context = app.Context;

// if the user belongs to adminsitrators role or reporting group
// redirect the user to
if (context.User.IsInRole(@"BUILTIN\Administrators") &&
context.User.IsInRole(@"LSS\ReportingGroup {0993772e-cfb6-47ba-8b88-2129bfc97f89}"))

if (_eventHandler != null)
_eventHandler(this, null);


Put the dll in the bin of the CRMWeb

..\Microsoft Dynamics CRM\CRMWeb\bin

And register the http module in the web.config

(use sn –T MyModule.dll to get the public key token)

Moreover this can be implemented using URLRewrite as it runs before the authentication so we wont be able to get the username

Hope it helps



Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

4 thoughts on “Sample HttpModule for CRM 2013 on premise.”

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.