أفضل الممارسات لتوليد WSP مع سياسة الوصول من التعليمات البرمجية

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/81379

  •  10-12-2019
  •  | 
  •  

سؤال

أنا أستخدم SharePoint 2007 و Visual Studio 2008. لقد غيرت بعض التعليمات البرمجية المخصصة في حل موجود.الآن انتهيت من التطوير وحاول إنشاء ملف WSP.هناك مشكلة واحدة فقط.أحتاج إلى إنشاء ملف WSP مع سياسة CAS وليس إلى GAC.الشخص الذي أنشأ هذا الحل كان يفعل ذلك بهذا السيناريو:

1) غير مسار الإخراج بناء إلى "80 \ bin".

2) قم بإصدار إصدار

3) توليد WSP مع BSP Builder

4) قم بتغيير امتداد ملف WSP الذي تم إنشاؤه إلى .cab

5) استخراج ملف الكابينة

6) ابحث عن وتعديل masterest.xml

7) قم بتغيير العنصر إلى: giveacodicetagpre.

8) احفظ الملف

9) إنشاء ملف الكابينة

10) إنشاء ملف WSP

أخبرني شخص ما أن هذا هو الحل السيئ للقيام بذلك.يجب أن يكون ممكنا مع Wspbuilder في سطر الأوامر.هل يمكن لأي شخص أن يقول لي كيف أفعل هذا؟

هل كانت مفيدة؟

المحلول

add this just above your public class file!

[SharePointPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, Impersonate = true)] 

[SharePointPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, ObjectModel = true)]

then let wspbuilder do the rest for you as it will build the xml file for you within the manifest file!

EDIT

The code that follows the call into the Demand method will be executed only if all the callers in the call stack are granted the permission to access the SharePoint object model. Note that this security demand has no impact on the code that comes before the call into the Demand method. The situation would be different if you were to use the declarative security syntax to annotate MyMethod with the SharePointPermissionAttribute metadata attribute:

   [SharePointPermission(SecurityAction.Demand, ObjectModel=true, Unrestricted=true)]
public void MyMethod()
{
   ...
   SPWeb site = SPContext.Current.Web;
   ...
}

in your case its the main class that contains the create child controls method, as an example:

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace test    {

    [SharePointPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, Impersonate = true)] 
    [SharePointPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, ObjectModel = true)]
    [ToolboxItemAttribute(false)]
    public class VisualWebPart1 : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/test/VisualWebPart1UserControl.ascx";

        protected override void CreateChildControls()
        {
            Control control = Page.LoadControl(_ascxPath);
            Controls.Add(control);
        }
    }
}

also it depends on what you want visible to the policy? as iv noted within the comment block. To my understanding its just the main class that needs the policy and not every class within the project!

http://msdn.microsoft.com/en-us/library/gg427711(v=office.12).aspx

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top