using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Administration;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace SPSiteHanlder.Features.WebFeature
{
/// <summary>
/// This class is used to handle the activation of 、 Discontinue use 、 install 、 Events raised during the process of uninstalling and upgrading features .
/// </summary>
/// <remarks>
/// Attached to this class GUID May be used during packaging , There should be no modification .
/// </remarks>

[Guid("aa46c131-e224-492a-a623-db98662fafcc")]
public class WebFeatureEventReceiver : SPFeatureReceiver
{
// Uncomment the following method , In order to handle the event raised after a function is activated .
private const string WebConfigModificatinOwner = "SPSiteHanlder.LogonModule";
private readonly SPWebConfigModification[] Modifications ={
new SPWebConfigModification(){
Owner=WebConfigModificatinOwner,
Name="add[@name='LogonModule']",
Type=SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
Path="configuration/system.webServer/modules",
Sequence=0,
Value=string.Format("<add name='LogonModule' type='SPSiteHanlder.LogonModule,{0}' />",Assembly.GetExecutingAssembly().FullName)
}
};
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
if (webApp != null)
{
AddWebConfig(webApp, Modifications);
}
}

// Uncomment the following method , To handle events raised before a function is disabled .

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
if (webApp != null)
{
RemoveWebConfig(webApp, "SPSiteHanlder.LogonModule");
}
}
/// <summary>
/// add to webconfig
/// </summary>
/// <param name="webApp"></param>
/// <param name="modifications"></param>
protected void AddWebConfig(SPWebApplication webApp,IEnumerable<SPWebConfigModification> modifications)
{
foreach (SPWebConfigModification a in modifications)
{
webApp.WebConfigModifications.Add(a);
}
webApp.Update();
webApp.WebService.ApplyWebConfigModifications();
}
protected void RemoveWebConfig(SPWebApplication webApp, string owner)
{
Collection<SPWebConfigModification> modifications = webApp.WebConfigModifications;
Collection<SPWebConfigModification> removeModifications = new Collection<SPWebConfigModification>();
int count = modifications.Count;
for (int i = 0; i < count; i++)
{
var a = modifications[i];
if (a.Owner == owner)
{
removeModifications.Add(a);
}
}
if (removeModifications.Count > 0)
{
foreach (SPWebConfigModification b in removeModifications)
{
webApp.WebConfigModifications.Remove(b);
}
webApp.Update();
webApp.WebService.ApplyWebConfigModifications();
}

}

// Uncomment the following method , To handle events raised after a feature is installed .

//public override void FeatureInstalled(SPFeatureReceiverProperties properties)
//{
//}

// Uncomment the following method , To handle events raised before a feature is unloaded .

//public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
//{
//}

// Uncomment the following method , In order to handle the event raised when a function is upgraded .

//public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
//{
//}
}
}

Sharepoint2010 adopt WebFeature modify web.config More articles about

  1. stay Web.Config Use... In the document configSource, Avoid dynamic modification web.config Lead to asp.net restart ( Add another Config Files are used to manage user data )

    original text : stay Web.Config Use... In the document configSource, Avoid dynamic modification web.config Lead to asp.net restart ( Add another Config Files are used to manage user data ) We all know , stay asp.net Revision in China ...

  2. C# obtain And modify web.config The value in ( modify Xml file )

    Definition web.config in appSettings node <appSettings> <add key="domainExist" value="fa ...

  3. modify web.config To open Gzip Compress

    IIS 7.0 The one introduced after that IIS The configuration file , Please refer to the official link for details http://www.iis.net/learn/get-started /planning-your-iis-architecture ...

  4. Give Way asp.net The program is changing web.config Don't restart after

    By default web.config After modification ,asp.net The program will be restarted . To prevent the program from restarting , To be modified machine.config file . machine.config Default in C:\WINDOWS\Microsof ...

  5. ASP.NET Dynamic modification in the program web.config Setting items in ( backstage CS Code )

    using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Dra ...

  6. stay VisualStudio 2012 Pass through SmallSharp Compress js And modification web.config

    Add a... To the project targets file , The name my.build.targets stay targets Add content to the file : <?xml version="1.0" encoding=&quo ...

  7. Asp.Net Modify upload file size limit ( modify web.config)

    i. Configuration Under the node <system.webServer> <security> <requestFiltering> <!-- The unit is byte   ...

  8. How to modify Web.Config The value of the inside

    0. To add <add key="MAXNUM" value="6" /> 1. Read the values string maxNum = ConfigurationMa ...

  9. asp.net modify web.config file

    private void UpdateConfigFile() { var cfg = System.Web.Configuration.WebConfigurationManager.OpenWeb ...

Random recommendation

  1. bzoj4498: The collision of magic

    First , If the permutation is determined , Then it can be solved by combinatorics , But there are a lot of permutations , Obviously you can't enumerate . We find that if the intervals don't overlap , The total length minus all the interval lengths is the number of extra cells that can be used . However, adjacent intervals may overlap half the length of the cells , So these ...

  2. yii gii Automatically generated curd Add batch delete instances

    1. In the view CGridView Medium columns add to , The function is to add multiple boxes   The code is as follows Copy code array(        'selectableRows' => 2,        'foot ...

  3. Follow someone else's example demo I tried to make a magnifying glass effect

    principle : A: Magnifier   B: Little picture C: Big picture viewable area D: Big picture The position of the mouse should be in the center of the magnifying glass , So the mouse position is :clientX=A.offsetLeft()+B.offsetLeft+1/2*A.o ...

  4. mysql The remote access

    How to open MySQL My remote account -1) First of all root Account landing MySQL stay Windows Click the start menu in the host , function , Input “cmd”, Access control , then cd Get into MySQL Of bin Under the table of contents , Then lose ...

  5. resolve &quot;Undefined attribute name&quot; warning for Angular &quot;ng-&quot; attributes in HTML files

    Because of these attributes Caused by the warning More , Affect intuitive search for other warning. So choose to put this kind of warning Ignore it : Project Property -> Validation ...

  6. JAVA adopt Gearman Realization MySQL To Redis Data synchronization for ( Asynchronous replication )

    MySQL To Redis Data replication solutions No matter what MySQL still Redis, It has its own data synchronization mechanism , Like the more commonly used  MySQL Of Master/Slave Pattern  , Is the Slave End analysis Master Of binlog Come on ...

  7. Bootstrap3 grid system - example : From stack to level

    Use a single set .col-md-* Grid class , You can create a basic grid system , It started as a stack of phones and tablets ( From ultra small screen to small screen ), On the desktop ( secondary ) The screen device changes to horizontal arrangement . all " Column ( ...

  8. AtCoder Regular Contest 069 F - Flags

    The question : Yes n A point needs to be placed on a number axis , Each point needs to be placed in ai This position or bi On , How can a pendulum maximize the minimum distance between two adjacent points on the number axis . After two answers, it's obviously a 2-sat Determine the problem , Because there are many sides, and there is an interval connecting the sides , the ...

  9. Linux epoll Version timer

    #ifndef __MYTIMER_H_ #define __MYTIMER_H_ /*************** Timer in high concurrency scenario *****************/ // Timer callback function t ...

  10. span What should I do when I wrap lines inside the text

    It can be used white-space:nowrap To force text not to wrap , Know to meet <br> until