سؤال

I have this in my master page.

<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="CreateSSCSite">
    <SharePoint:CssLink runat="server" Version="4"/>
</Sharepoint:SPSecurityTrimmedControl>

If the user meets the permissions then it returns:

<span>
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
</span>

How can I make it not return those infernal span tags?

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

المحلول

Adding to iambriansreed's solution, you can put the comments in Literal controls around the SPSecurityTrimmedControls to prevent SPD from adding the extra rubbish. For example:

<asp:Literal runat="server" text="&lt;!-- "/><SharePoint:SPSecurityTrimmedControl PermissionsString="EditListItems" runat="server"><asp:Literal runat="server" text=" --&gt;"/>
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
<asp:Literal runat="server" text="&lt;!-- "/></SharePoint:SPSecurityTrimmedControl><asp:Literal runat="server" text=" --&gt;"/>

It's a bit annoying, but simpler than writing a new control.

If you're using SharePoint 2013's Publishing Infrastructure, the same example will look like this on an HTML master page:

<!--SPM:<asp:Literal Text="&lt;!&#45;&#45; " runat="server" />-->
<!--MS:<SharePoint:SPSecurityTrimmedControl runat="server" Permissions="CreateSSCSite">-->
<!--SPM:<asp:Literal Text=" &#45;&#45;&gt;" runat="server" />-->
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
<!--SPM:<asp:Literal Text="&lt;!&#45;&#45; " runat="server" />-->
<!--ME:</SharePoint:SPSecurityTrimmedControl>-->
<!--SPM:<asp:Literal Text=" &#45;&#45;&gt;" runat="server" />-->

نصائح أخرى

The easiest and cleanest way to do this is wrap the control with html comments:

<!-- <Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="CreateSSCSite"> -->
    <SharePoint:CssLink runat="server" Version="4"/>
<!-- </Sharepoint:SPSecurityTrimmedControl> -->

If the user meets the permissions then it returns:

<!-- <span> -->
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
<!-- </span> -->

Super simple.

You should be able to create your own control inheriting from Sharepoint:SPSecurityTrimmedControl and override RenderBeginTag and RenderEndTag to do nothing

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