locked
Configuring HTTPModule at WebSite level RRS feed

  • Question

  • User-1514415097 posted

    Hi,

    I have written a HTTPModule extending IHTTPModule. Can this HTTPModule be installed for a website instead of a virtual directory in IIS.

    Like for the whole DefaultWebSite.

    Thanks

    Sai Prasad

    Monday, September 19, 2011 6:03 AM

Answers

  • User-1175076010 posted

    Well, I understood your problem now. As this HTTPModule is going to be common for all the virtual directories, I think you need to add your HTTPModule dll to the GAC.

    Can you try adding your dll to GAC, so that it would be referenced in all your virtual directories.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 19, 2011 11:19 PM

All replies

  • User-1175076010 posted

    Register your HTTPModule in the machine.config file. Below link may help you.

    http://stackoverflow.com/questions/4078326/httpmodule-over-multiple-sites

    http://msdn.microsoft.com/en-us/library/ms227673.aspx

    Monday, September 19, 2011 7:01 AM
  • User-1514415097 posted

    Hi Rajganesh,

    Thanks for the reply.

    I have added my custom HTTPModule in web.config file for the web site.

           <httpModules>
    <add type="CustomModule.CusotmModule"
    name="CustomModule"/>

    </httpModules>
    When I try to access a virtual directory under the web site its trying to load CustomModule.CustomModule. 
    And throwing an error 
    
    
    Exception information: 
    Exception type: ConfigurationErrorsException
    Exception message: Could not load type 'CustomModule.CusotmModule'. (c:\inetpub\wwwroot\web.config line 5) (c:\inetpub\wwwroot\web.config line 5)
    Monday, September 19, 2011 7:40 AM
  • User-1175076010 posted

    Have you added the reference to the CustomModule.CusotmModule in your website?

    Monday, September 19, 2011 7:51 AM
  • User-1514415097 posted

    Sorry I didnt understand about adding reference.

    How to add the reference.

    Thanks

    Sai Prasad

    Monday, September 19, 2011 7:59 AM
  • User-1175076010 posted

    Is the code for HTTPModule is available under the App_Code directory of the website or is it an external dll?

    If it is an external dll file you need to add the reference to the dll file in your website.

    Monday, September 19, 2011 8:08 AM
  • User-1514415097 posted

    It is an external dll. 

    Sorry for the following question I am new to this IIS and HTTPModules

    How to add reference to the dll in the website. 

    My HTTPModule is also dependent on other dlls.

    Thanks

    Sai Prasad

    Monday, September 19, 2011 8:15 AM
  • User-1175076010 posted

    As it is an external dll, you need to add the reference to the dll to the website.

    Check the below link to learn more about adding reference.<o:p></o:p>

    http://msdn.microsoft.com/en-us/library/wkze6zky.aspx<o:p></o:p>

    http://msdn.microsoft.com/en-us/library/7314433t(v=vs.90).aspx<o:p></o:p>

    Monday, September 19, 2011 8:19 AM
  • User-1514415097 posted

    Rajganesh,

    May be I was not clear in explaining my issue.

    Links you have provided are showing how to add references of a external dll to asp.net applications I create in visual studiol

    Here is the issue I am facing.

    Under IIS WebSites we have Default Web Site. I have created External Web Site under WebSites with a different IP.

    There are virtual directories under both the Default and External web site. I have to apply a custom HTTPModule to only Default Web Site.

    If the user access any virtual directory under Default web site the modules kicks in.

    If the user access any virtual directory under External web site module shoud not do anything.

    So I thought may be this HTTPModule can be configured at the WebSite level instead for each virtual directory.

    I created a config file under Default Web Site root folder where I have provided configuration for the HTTPModule.

    When I a hit virutal directory URL from browser its trying to load Module but failing with the exception I have sent earlier.

     Sorry for the confusion created.

    Thanks

    Sai Prasad

    Monday, September 19, 2011 9:04 AM
  • User-1175076010 posted

    Well, I understood your problem now. As this HTTPModule is going to be common for all the virtual directories, I think you need to add your HTTPModule dll to the GAC.

    Can you try adding your dll to GAC, so that it would be referenced in all your virtual directories.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 19, 2011 11:19 PM
  • User-591886447 posted

    i copied dll in GAC,after that registered the dll in web.config but it is not working.

    <add name="modulename"  type="httphandler1.handlerclass,httphandler1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f62e909d171324d"/>

    it is showing error

    Could not load file or assembly 'httphandler1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f62e909d171324d' or one of its dependencies. The system cannot find the file specified. (D:\WebSite17\web.config line 75)

    Tuesday, November 22, 2011 1:22 AM
  • User1622957740 posted

    Just for clarification:

    When you add a module to the root of your Web site, it's visible to all child virtual directories.

    As such you have to make sure the module is available to run in all child virtuals (ie. either in the BIN folder or the GAC)

    You can explicitly remove the module from child virtuals with the <remove> key in the handlers section if you don't want it to fire in the child virtual.

    +++ Rick ---

    Monday, December 5, 2011 6:53 PM