Search code examples
asp.netvisual-studio-2013httpmodulesitefinityiis-8.5

Unable to debug httpModule of a sitefinity site hosted in IIS 8.5 using Visual Studio 2013


I'm trying to debug a httpModule of a sitefinity site which is hosted in IIS 8.5 using Visual Studio 2013. I'm using Sitefinity 8.1 for site development.

Things that I've done till now:

  1. Created a httpModule under the root folder of the sitefinity site. Code as follows:
public class UserRoleHttpModule : IHttpModule
{            
    public void Init(HttpApplication application)
    {
        application.PostAuthenticateRequest +=
            (new EventHandler(this.PostAuthenticateRequest));
    }

    private void PostAuthenticateRequest(Object source,
                                         EventArgs e)
    {
        UserManager userManager = UserManager.GetManager();
        RoleManager roleManager = RoleManager.GetManager(SecurityManager.ApplicationRolesProviderName);
        roleManager.Provider.SuppressSecurityChecks = true;

        string[] rolesToAdd = new string[] {"BackendUsers"};

        if (userManager.UserExists("rahuln"))
        {
            User user = userManager.GetUser("rahuln");

            foreach (var roleName in rolesToAdd)
            {
                if (roleManager.RoleExists(roleName))
                {
                    Role role = roleManager.GetRole(roleName);
                    roleManager.AddUserToRole(user, role);
                }
            }
        }

        roleManager.SaveChanges();
        roleManager.Provider.SuppressSecurityChecks = false;
    }          

    public void Dispose()
    {
    }
}
  1. Registered module under webconfig
<modules runAllManagedModulesForAllRequests="true">        
            <remove name="UserRoleHttpModule" />
            <add name="UserRoleHttpModule" type="SitefinityWebApp.UserRoleHttpModule"/>
</modules>

Now when I run the page from IIS and do the "attach to process" with w3wp.exe in visual studio. I never get a hit on my break points in httpModule. I tried building the solution and the build was successful.

Any help will be greatly appreciated.

Thanks


Solution

  • Are you sure the HttpModule is executing, to verify add the following to PostAuthenticateRequest and it should redirect to microsoft.com if it is.

    HttpApplication application = (HttpApplication)source;
    HttpContext context = application.Context;
    context.Response.Redirect("http://www.microsoft.com");