简体   繁体   中英

WSPBuilder and Code behind for a Sharepoint Masterpage

I created a code behind file for a custom master page in visual studio. I hooked everything up manually; safe control and custom cas policy. Everything works great!

I then wanted to put this into a sharepoint solution using WSPBuilder for better deployment. I created WSP solution, added my class file and changed the output directory to the bin folder. 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.'

This has me stumped as it works as a visual studio class file deployed to the bin directory of the website. However when I put this into a sharepoint solution it breaks! I tried adding

'[assembly: System.Security.AllowPartiallyTrustedCallers]'

to the AssemblyInfo.cs but this hasn't helped.

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:

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

or in WSPBuilder config:

<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!).

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.

What is the trust in your web.config file set to? 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. 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? If there are two assemblies the one in GAC takes precedence.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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