Sharepoint 2013
Steps to recreate issue:
1.) Following the steps from this blog... https://sharepointgotchas.wordpress.com/tag/httpmodule/
I started with an Empty SP solution. I created an HTTP module by adding a class to the project.
2.) I created a web application-scoped feature (call it F1) and event receiver (call it ER1) that would register the HTTP module upon activation of the feature.
(Note: When I open the feature, there is nothing shown in the "Items in the Solution" and therefore nothing to move into the "Items in the Feature". I believe this is how it should work...? The httpmodule isn't part of the feature, it's just used by the feature event receiver when the feature is activated)
3.)I deployed the solution using VS2012.
4.)Then, I retracted and removed the solution using Sharepoint Shell.
5.)I opened the solution again, and I think I removed the feature (F1) from the solution.
6.)I created a new feature (F2) and a new event receiver (ER2), and added it to the solution.
7.)I deployed the solution again using VS2012. There is only 1 Event Receiver (ER2) in my solution.
The Issue: When I activate the feature in Central Admin > Manage Web Applications, I am expecting the code from ER2 to fire, but the code from both ER1 and ER2 is firing.
More details/code on the EventReceiver...
This was the first Event Receiver:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
SPWebConfigModification modification = new SPWebConfigModification("add[@name='HTTPMODULE1']", "configuration/system.webServer/modules");
modification.Sequence = 0;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Value = string.Format(@"<add name=""HTTPMODULE1"" type=""Redirect.HTTPMODULE1, {0}"" />", Assembly.GetExecutingAssembly().FullName);
webApp.WebConfigModifications.Add(modification);
webApp.Update();
webApp.WebService.ApplyWebConfigModifications();
}
This was the second Event Receiver (ER2), exactly the same as ER1 except the name of the HTTP module I am registering is different:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
SPWebConfigModification modification = new SPWebConfigModification("add[@name='HTTPMODULE2']", "configuration/system.webServer/modules");
modification.Sequence = 0;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Value = string.Format(@"<add name=""HTTPMODULE2"" type=""Redirect.HTTPMODULE2, {0}"" />", Assembly.GetExecutingAssembly().FullName);
webApp.WebConfigModifications.Add(modification);
webApp.Update();
webApp.WebService.ApplyWebConfigModifications();
}
Troubleshooting:
I have read and tried everything that I can find. It seems to be a common issue with not a lot of solutions that work.
If you link me to something, please refer to something specific in the link because chances are I've already read it.
I've tried doing a OWSTimer reset, an ISSReset, I've used gacutil to verify the assemblies are actually getting removed when they should be and re-installed when they should be. I have tried upgrading the feature instead of re-deploying.
I've tried deploying from VS2012 and from the shell.
I've used the Process Explorer tool, though I'm not entirely sure I'm using it correctly.
Actual troubleshooting steps:
1.) In Central Admin at the Web Application Level, I Deactivate the Feature.
2.) In Sharepoint shell, I run Uninstall-SPSolution -Identity MySolution.wsp and Remove-SPSolution -Identity MySolution.wsp
3.) I verify with Get-SPSolution that MySolution.wsp does not exist.
4.) I run gacutil /l with Developer Command Prompt for VS2012 and verify that MySolution does not exist in the GAC.
5.) I close Sharepoint shell and VS2012, and Central Admin.
6.) Process Explorer shows 0 results found when I do a Search for a DLL and search for MySolution.
7.) I reopen Sharepoint shell and run:
restart-service sptimerv4
I close and reopen the shell again.
8.) I search for IISReset from Windows Search and run that.
9.) I re-open the solution in VS2012, and re-deploy it.
10.) I run Get-SPSolution to verify that my solution exists and is installed
11.) I run gacutil /l to verify that my assembly is in GAC.
12.) I do another timer reset as above and reset IIS.
13.) I open Central Admin, Manage Web applications, and reactivate the feature. The code from ER1 and ER2 is still firing.
14.) I use Process explorer and do another search for the DLL/handle. It shows 2 rows, 1 with a file and 1 with the DLL used by the w3wp.exe process, and I think this is correct.
Help. I'm losing my mind. What I want to happen actually happens - ER2 fires, but I don't want ER1 to fire.
Is there a way that I can see which event handler or dll is being referenced when I activate the feature? Can I get a trace or log file? How?
If I can't get this to work, I'm probably going to rollback, create a whole new solution and feature/event handler and go from there.
But I don't understand what's causing the issue.
Edit: My scenario is not exactly like the blog. I don't have a list, it's much simpler. There are no items in the feature. I just want the event receiver to add the http module to the web.config of the web application when the feature is activated, which it does in ER2. But it is also adding the first http module, firing code that I had written in ER1. In other words, I did this, but I have a different problem: Activating a WebApplication Scoped Feature for a particular WebApplication