Packaging A SharePoint 2010 Custom Claims Provider in a Visual Studio 2010 SharePoint Project


For those of you who have been developing solutions for SharePoint 2010 with Visual Studio 2010, you may have noticed a slight packaging peculiarity when it comes to custom claims providers.  In Visual Studio 2010 you can create a new feature and you can easily add a feature event receiver to it by just right-clicking on the feature and selecting the Add Event Receiver menu.  That’s nice because it’s very easy and productive to get working on the coding for your solution rather than the configuration.  The disconnect comes in because the event receiver it adds by default inherits from SPFeatureReceiver.  As I’m sure you all know, the event receiver used to register a custom claims provider must inherit from SPClaimProviderFeatureReceiver (http://blogs.technet.com/b/speschka/archive/2010/03/13/writing-a-custom-claims-provider-for-sharepoint-2010-part-1.aspx).  In addition, the built in SharePoint smarts in Visual Studio don’t lend itself to a really intuitive way to just add a class to a SharePoint 2010 project and then have it associated with a feature.  There is however a fairly easy and slick way around this.
I went down this path a while ago when I was beginning with my usual starting point – I had a custom claims provider I had written and corresponding feature receiver to install it.  These two classes were part of a single project.  I decided that I really wanted to make the new feature packaging goo in Visual Studio 2010 work for me, so here’s how I did it.

1.       Complete your first run at your custom claim provider project and corresponding event receiver for registration, then compile it.  You want to look at the compiled assembly and get the strong name for the assembly as well as the class name for the event receiver.

2.       Add a new project to your solution, and base it on a SharePoint 2010 “Empty SharePoint Project” template.  Configure the project to be deployed as a farm solution.

3.       Right click on the Features node in the project and select Add Feature.  Your feature should be scoped to Farm and should auto activate.  Otherwise, configure the feature properties as appropriate for what you are trying to do.  Here is the important point – configure these two properties on the feature (in the Visual Studio Properties window) as described:

a.       Receiver Assembly:  put in the strong name to your assembly described in step #1, for example MyClaimProvider.ClaimTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=edb00fee02fa0701

b.      Receiver Class:  put in the name of the class that you wrote your custom claims provider in step #1, for example MyClaimProvider.ClaimTest.MyClaimsFeatureReceiver

4.       Add your compiled custom claims provider assembly to the list of assemblies your packaging solution is going to deploy.  To do this, double-click on the Package.package node in the Visual Studio packaging project.  Click on the Advanced tab.  Click on the Add button, then the Add Existing Assembly menu.  Find the correct location for your compiled custom claims provider assembly, and leave the Deployment Target: GlobalAssemblyCache selected (it is by default).  Click the OK button to save your changes and then you can close the Package properties window.  One thing to note here – I usually just create a folder in my packaging project where I copy my compiled assemblies from other projects that I want to be distributed with the solution.  When I configure the additional assemblies in the Package, I just select from the folder in my packaging project.  In my other projects, I have a post-build script that automatically copies the compiled assembly into this assembly folder in my packaging project.  It’s a simple one line of code post-build that copies the assembly whether it’s a debug or release build so I don’t need to remember to do it myself each time.  It looks like this: 

copy "$(TargetPath)" ..\..\..\MyPackagingProject\GacFiles /Y
Your package is now complete.  You just need to compile the package project and then select the Package menu from the right-click menu for the project.  You’ll end up with a WSP file that you can then distribute and have it automatically roll out your custom claims provider.

Packaging A SharePoint 2010 Custom Claims Provider in a Visual Studio 2010 SharePoint Project.docx

Comments (3)

  1. alexandrad9x says:

    Tao http://dichvuketoanlongbien.com/
    Rủa
    http://dichvuketoanlongbien.com/a2-96-dich-vu-ke-toan-tron-goi.html
    Thằng http://dichvuketoanlongbien.com/a2-98-dich-vu-ke-toan-thue.html
    Cờ
    http://dichvuketoanlongbien.com/a2-103-dich-vu-bao-cao-tai-chinh.html
    http://dichvuketoanlongbien.com/a2-97-dich-vu-quyet-toan-thue.html
    Nào
    http://dichvuketoanlongbien.com/a2-114-dich-vu-ke-toan-tai-29-quan-huyen.html
    Soi
    http://dichvuketoanlongbien.com/i780-dich-vu-ke-toan-thue-tron-goi-tai-bac-ninh.html
    Tài
    http://dichvuketoanlongbien.com/i779-dich-vu-ke-toan-thue-tron-goi-tai-bac-giang.html
    Khoản
    http://dichvuketoanlongbien.com/i778-dich-vu-ke-toan-thue-tron-goi-tai-phu-tho.html

    http://dichvuketoanlongbien.com/i781-dich-vu-ke-toan-thue-tron-goi-tai-hung-yen.html
    Link
    http://dichvuketoanlongbien.com/i782-dich-vu-ke-toan-thue-tron-goi-tai-vinh-phuc.html
    Của
    http://dichvuketoanlongbien.com/i783-dich-vu-ke-toan-thue-tron-goi-tai-hai-phong.html
    Tao. http://www.trungtamketoan.com.vn/
    Chúng
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-ha-noi.html
    Mày
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-tp-hcm.html
    Đủ
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-quang-ninh.html
    Trình
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-duong.html
    Thì
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-giang.html
    Tự
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-ninh.html
    Đi
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-phong.html

    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-nam-dinh.html
    Làm.
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thai-binh.html
    Việc
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thanh-hoa.html

    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-vinh-phuc.html
    Phải
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hung-yen.html
    Rẻ
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-phu-tho.html
    Rách
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-binh-duong.html
    Như http://www.tosvn.com
    Thế. http://iketoan247.blogspot.com
    Loại http://tailieuveketoan.blogspot.com
    Chó http://mauhinhnendep.blogspot.com
    Má. http://www.tosvn.com/search/label/Hack%20CF
    Tao http://www.tosvn.com/search/label/Hack%20AvatarStar
    Rủa http://www.tosvn.com/search/label/Hack%20Warcraft-Dota2
    Những http://hocketoan360.com/category/tai-lieu-ke-toan/
    Thằng http://iketoan247.blogspot.com/search/label/thong-tin-kinh-te
    Soi http://iketoan247.blogspot.com/search/label/tin-bai-ve-thue
    Tao http://hoclamketoan.edu.vn/
    Sẽ http://hoclamketoan.edu.vn/category/khoa-hoc-ke-toan
    Tan http://hoclamketoan.edu.vn/category/dich-vu-ke-toan
    Cửa http://hoclamketoan.edu.vn/category/hoc-lam-ke-toan
    Nát http://hoclamketoan.edu.vn/category/tai-lieu-ke-toan
    Nhà http://hocketoan360.com/
    Haha http://hocketoan360.com/category/khoa-hoc-ke-toan/
    http://hocketoan360.com/category/dich-vu-ke-toan/

  2. vivek says:

    Hi Steve,

    Thanks for such an informative series on custom claims provider.

    I've few queries regarding this.

    1. Is there any way to remove our custom claims provider when we deactivate the feature?

    2. Is there any way we can use claim values while setting up "target audience"?

    3. We need to test diff scenarios: checking the site behavior when

      a. user is associated with claim1, claim2.

      b. user is associated with claim3, claim4. claim5.

    This mapping of claims to user id is done in backend.

    Right now what I'm observing is that, after iisreset when user logs in for the first time; our claims provider gets executed and ,say, Claim1 and Claim2 get added; Now user signs out of SP UI; closes the browser window; Updates claims associated with user in backend; and accesses the URL of the site in new browser window. This time our claims provider doesn't get executed and user ID continues to have claim1 and claim2 associated with it.

    Did you face such issue? how do we test different scenarios.

  3. AFS says:

    http://www.shopbestgoods.com/
    http://www.nike-jordanshoes.com/
    http://www.beatsbydreoutlet.net/
    http://www.michaelkorsus.com/
    http://www.polo-tshirts.com/
    http://www.northsclearance.com/
    http://www.ralph-laurensale.com/
    http://www.gucci-shoesuk2014.com/
    http://www.michael-korsusa.com/
    http://www.polo-outlets.com/
    http://www.ralphslauren.co.uk/
    http://www.marcjacobsonsale.com/
    http://www.mcmworldwides.com/
    http://www.salongchamppairs.com/
    http://www.canada-gooser.com/
    http://www.burberryoutlet2014.com/
    http://www.michaelkors.so/
    http://www.hermes-outletonline.com/
    http://www.oakley-sunglassoutlet.com/
    http://www.north-faceoutlets.net/
    http://www.moncler-clearance.com/
    http://www.woolrich-clearance.com/
    http://www.barbour-jacketsoutlet.com/
    http://www.moncler-jacketsoutletonline.com/
    http://www.monsterbeatsbydres.net/
    http://www.louis-vuittonblackfriday.com/
    http://www.lv-guccishoesfactory.com/
    http://www.mcmoutlet-jp.com/
    http://www.cheapdiscountoutlet.com/
    http://coachoutlet.iwopop.com/
    http://www.coachsfactoryoutlet.com/
    http://www.coach-blackfriday2014.com/
    http://www.coach-storeoutletonline.com/
    http://www.coach-factorysoutletonline.com/
    http://www.coachccoachoutlet.com/
    http://www.coach-factories.net/
    http://www.coach-pursesoutletonline.com/
    http://www.llouisvuitton-factory.net/
    http://www.coach-outletsusa.com/
    http://www.mksfactoryoutlet.com/
    http://www.zxcoachoutlet.com/
    http://www.mischristmas.com/
    http://www.misblackfriday.com/
    http://www.bestcustomsonline.com/
    http://www.newoutletonlinemall.com/
    http://www.clickmichaelkors.com/
    http://www.cmichaelkorsoutlet.com/
    http://www.ralphlaurenepolo.com/
    http://michaelkorsoutlet.mischristmas.com/
    http://mcmbackpack.mischristmas.com/
    http://monsterbeats.mischristmas.com/
    http://northfaceoutlet.mischristmas.com/
    http://mk.misblackfriday.com/
    http://coachoutlet.misblackfriday.com/
    http://coachfactory.misblackfriday.com/
    http://uggaustralia.misblackfriday.com/
    http://coachpurses.misblackfriday.com/
    http://coachusa.misblackfriday.com/
    http://coach.misblackfriday.com/
    http://michaelkorss.misblackfriday.com/
    http://michaelkors.misblackfriday.com/
    http://airmax.misblackfriday.com/
    http://michael-kors.misblackfriday.com/

    http://t.co/1PJuejI1ys
    http://t.co/FYm2MxWwLM
    https://twitter.com/CoachOutlet2014
    https://www.facebook.com/pages/Coach-Factory-Outlet-Online-Store-Michael-Kors-Outlet-Online-Sale-75-Off/712060898859091
    https://www.facebook.com/pages/Ralph-Lauren-Polo-Outlet-Online-Sale/1404100279810690