Daniel's profileDaniel Larson's Develope...BlogListsGuestbookMore Tools Help

Blog


    January 09

    Adding http handlers to web.config in solution packages

    While there isn't any Solution Package items to add httpHandlers and other web.config edits, you can do these through Feature Receivers. Tony pointed this out in his post @ sharepointsolutions.blogspot.com, so I decided to update the code for the Atlas RC and add it to a Feature Reciever in the SharePoint.Ajax Codeplex Project. Otherwise, I've got this great installer technology that scales well across farms and enables no-touch dpeloyment EXCEPT for that httpHandler. That's really a bummer-- so I'm glad to have found a solution! We now have a complete no-touch deployment solution in place for the SharePoint Ajax components, which isn't bad for such a "young" project this early in development!

    The Feature Reciever is defined in the Feature manifest with the following attributes:

    ReceiverAssembly="SharePoint.Ajax, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ed42c8fcfe5cf7c"
    ReceiverClass="SharePoint.Ajax.Config.FeatureReceiver"

    This seems to work well in the Solution Package when the Feature is set to the SPWeb's scope, when handling the FeatureActivated method. It is now standard part of my Ajax project's Solution Package projects, including SharePoint.Ajax on Codeplex.  If you'd like to see the full source code, it's in change set 15970 or newer.

    public const string ScriptResource = 
    @"<add verb=""GET,HEAD"" path=""ScriptResource.axd""
    type=""System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35""
    validate=""false"" />"; public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication app = null; SPSiteCollection site = properties.Feature.Parent as SPSiteCollection; if (site == null) { SPWeb web = properties.Feature.Parent as SPWeb; if (web != null) app = web.Site.WebApplication; } else app = site.WebApplication; bool removeModification = false; if (app != null) AddAjaxHandlerToWebConfig(app, removeModification); else throw new ApplicationException("Could not locate a web application"); } public static void AddAjaxHandlerToWebConfig(SPWebApplication app, bool removeModification) { SPWebConfigModification modification = new SPWebConfigModification( "add[@path='ScriptResource.axd']", "configuration/system.web/httpHandlers"); modification.Owner = "SharePoint.Ajax"; modification.Sequence = 0; modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; modification.Value = ScriptResource; if (removeModification) app.WebConfigModifications.Remove(modification); else app.WebConfigModifications.Add(modification); SPFarm.Local.Services.GetValue().ApplyWebConfigModifications(); }

    Again, thanks to Tony for the original post.

    *Note: typo in AddAjaxHAndlerToWebConfig fixed on 1/10. Original post on 1/9.

    Comments (9)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    No namewrote:

    Hi,Do you need advertising displays, screen advertisings, digital sign, digital signages and LCDs? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

    amberdigital Contact Us

    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[bgabhcidighdca]

    Sept. 28
    Sept. 1
    July 16
    June 23
    June 17
    Mar. 1
    hi Daniel,

    I use this feature to install handlers, but I had a question.  I have a handler that references an assembly in the GAC.  When I install using your code, it puts the handlers in the web.config, but can't find the assemblies.  When I move those handlers to the web.config in the http://localhost/_wpresources folder, it works just dandy.

    Is there a way to pop that handler in there instead of in the web.config right in my virtual directory?  Or am I missing something?

    Thanks.

    Aug. 3
    When you add a new server to the farm, those events shouldn't fire again. The data is all in the content db-- so WSS just looks at configurations from teh config db (including SPWebConfigModifications) and extends the new server with those IIS sites and web configs. Also, solutions deployed to the original server should get pushed to the new server. It's because of this model that no-touch deployments using WSS standard technology is the preferred way to deploy applications.
    Mar. 22
    Mark Joneswrote:
    hi Daniel
     
    I am not quite sure how Sharepoint deals with features when you add new servers into the farm (after the initial feature to update the web.config is activated). As you add the new server to the farm, does the featureActivated/Installed fire again on that new server ? i guess it would be nice if it did, but then again if you put some code in your feature that updates sharepoint permissions for example, you would want this run against the content db again. Any ideas ? Is there an event when the solution package is deployed to the box as that would be the ideal ?
     
    Cheers
    Mark
    Mar. 21

    Trackbacks

    The trackback URL for this entry is:
    http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!916.trak
    Weblogs that reference this entry
    • None