Sign an Assembly with a strong Name

•Sign an Assembly with a strong Name

1.Create the Web Part. (The steps are the same as the last summary.)

2.Strong Naming a Web Part Assembly. Strong naming uses a private key to digitally sign an assembly. Strong naming also stamps the assembly with a public key to validate the signature. This technique guards against unauthorized versions of a Web Part. If the public key fails to validate the digital signature, SharePoint Foundation refuses to run the module. To sign an assembly, you use the sn.exe tool that is included with the Microsoft .NET Framework Software Development Kit (SDK). The Assembly Name property of an application determines the name that will be used for the compiled application. For example, setting the Assembly Name to "MyApplication" for a Windows-based application would result in an executable file named MyApplication.exe. The Assembly Name defaults to the project name; it can be changed on the Application page of the Project Designer.

In VS2010, right-click the properties of the project, in the signing option, tick the sign the assembly, and add the name. At last you will see the *.snk file.

 

 3.Sign assembly in GAC. (Instead of Step2 in last summary.) 

4.Make entry of the Web Part into web.config file. After assembly added to the cache successfully, navigate to C:\Windows\assembly, you will see the corresponding assembly.   Navigate to C:\Inetpub\wwwroot\wss\VirtualDirectories\80, open the web.config and add the class library name in the ‘SafeControls’ section.   Make sure that the PublicKeyToken, Version, Assembly Name and so on are corresponding to the information of assembly in GAC.

5.Add it to the Web Part gallery.

6.Add the Web Part to site pages.

 

•There are multiple locations within a SharePoint site where you can deploy a Web Part assembly.

1.Solution Gallery—The Solution Gallery is the recommend placed to deploy a Web Part by using a sandboxed solution. It provides monitoring and security for your Web Parts by default.

2.global assembly cache— A global location where signed assemblies can be deployed, especially code for workflows, events, and Feature receivers. The global assembly cache enables you to share assemblies across numerous applications. The global assembly cache is automatically installed with the .NET runtime. Components are typically stored in C:\Windows\Assembly.

3.bin directory — A folder stored in your web application root directory; deployment to the bin directory should be limited to controls and Web Parts . The location of this folder is determined when the website is created in Internet Information Services (IIS). In SharePoint Foundation, this can occur either through the Central Administration site, or by manually creating a new website in IIS manager.By default, code access security permissions for the bin directory are low; only pure execution is allowed. In most cases, you must elevate these permissions to make your assembly run correctly.

 

•There are two ways to elevate permissions:

1.Recommended method —Create a new trust policy file and point your web.config file at the new file. This option is more complicated but it gives you a precise attribution of permissions for your Web Parts.

2.Optional method —Raise the trust level of the bin directory. In the web.config file in the web application root, there is a tag named <trust> with a default attribute of level="WSS_Minimal". You can change this level to WSS_Medium. Although this option is simpler, it grants arbitrary new permissions that you might not need and is less secure than creating a new trust policy file. code access security (CAS)

 

Reference Sites:

Assembly Gacutil.exe

http://msdn.microsoft.com/en-us/library/ex0ss12c(v=vs.80).aspx

Deploying Web Parts in SharePoint Foundation

http://msdn.microsoft.com/en-us/library/cc768621.aspx

http://www.builder.com.cn/2008/0706/964938.shtml

http://msdn.microsoft.com/en-us/library/618ayhy6.aspx

http://msdn.microsoft.com/en-us/library/z2kcy19k(v=vs.80).aspx

http://www.xland.com.cn/article/7/12/0601/7705.htm

Vedio

http://msdn.microsoft.com/en-us/sharepoint/ee513148

 

posted @ 2012-05-24 00:59  l'oiseau  阅读(752)  评论(0编辑  收藏  举报