简体   繁体   English

WSPBuilder和用于Sharepoint母版页的代码

[英]WSPBuilder and Code behind for a Sharepoint Masterpage

I created a code behind file for a custom master page in visual studio. 我在Visual Studio中为自定义母版页创建了文件背后的代码。 I hooked everything up manually; 我把所有东西都手工挂钩了。 safe control and custom cas policy. 安全控制和自定义cas策略。 Everything works great! 一切正常!

I then wanted to put this into a sharepoint solution using WSPBuilder for better deployment. 然后,我想使用WSPBuilder将其放入共享点解决方案中,以实现更好的部署。 I created WSP solution, added my class file and changed the output directory to the bin folder. 我创建了WSP解决方案,添加了我的类文件,并将输出目录更改为bin文件夹。 I then built the solution and deployed it, making sure to change the page directives on the master page to reflect the new assembly name. 然后,我构建了解决方案并进行了部署,请确保更改母版页上的页面指令以反映新的程序集名称。

Now when I go to view the sharepoint site I get an error stating Security Exception error stating 现在,当我去查看共享点站点时,出现错误,指出“安全异常”错误说明

'Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.' “异常详细信息:System.Security.SecurityException:该程序集不允许部分受信任的调用方。”

This has me stumped as it works as a visual studio class file deployed to the bin directory of the website. 这让我感到很困惑,因为它可以作为Visual Studio类文件部署到网站的bin目录中。 However when I put this into a sharepoint solution it breaks! 但是,当我将其放入SharePoint解决方案中时,它就会崩溃! I tried adding 我尝试添加

'[assembly: System.Security.AllowPartiallyTrustedCallers]' '[程序集:System.Security.AllowPartiallyTrustedCallers]'

to the AssemblyInfo.cs but this hasn't helped. 到AssemblyInfo.cs,但这没有帮助。

Anyone else experinced this or have any advice? 有人对此有经验或有任何建议吗?

EDIT: I should also mention that the code behind is trying to access a sharepoint list. 编辑:我还应该提到,背后的代码正在尝试访问共享点列表。

Don´t you still have to include the SafeControls entry in order for it to work, like: 您仍然不需要包括SafeControls条目才能使其正常工作,例如:

<SafeControl Assembly="[FullAssembly Name]"
                     Namespace="[YourMasterPageNamespace]"
                     TypeName="*"
                     Safe="True" />

or in WSPBuilder config: 或在WSPBuilder配置中:

<add key="BuildSafeControls" value="True" />

Never seen this.. but I suspect not many people have created codebehinds to the master pages in SharePoint (Microsoft doesn't too!). 从来没有见过..但是我怀疑没有多少人在SharePoint的母版页中创建代码隐藏(Microsoft也不是!)。

I don't know what you are trying to build but I'd probably implement it using a server control that is included on the master page. 我不知道您要构建什么,但是我可能会使用母版页中包含的服务器控件来实现它。

AllowPartiallyTrustedCallers has always fixed it for my server controls. AllowPartiallyTrustedCallers始终为我的服务器控件修复它。

What is the trust in your web.config file set to? 您对web.config文件设置的信任是什么? Try Full. 尝试完整。

您可以尝试检查自己是否使用了完全合格的部分名称,包括正确的公钥标记和程序集的名称空间。

Are you calling a third party assembly? 您在打电话给第三方大会吗?

I ran into a situation recently that I was using a third party assembly and it did not have AllowPartiallyTrustedCallers in its code. 最近,我遇到了一种情况,我正在使用第三方程序集,但其代码中没有AllowPartiallyTrustedCallers When I tried to use the assebmly, it would fail. 当我尝试使用组装时,它会失败。

Are you sure that the assembly has been deployed to bin and no to GAC by accident? 您确定该程序集已被意外部署到bin而不是已部署到GAC吗? If there are two assemblies the one in GAC takes precedence. 如果有两个程序集,则GAC中的一个优先。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM