Friday, March 27, 2009

In-Line Script in SharePoint Page

You could add in-line script to a SharePoint page or Page template.

<asp:Content ID="main" runat="server"  ContentPlaceHolderID="PlaceHolderMain">
<% Response.Write("Hello Sanjay Sansanwal"); %>
</asp:Content>

You would able to access this page without error provided this page is ghosted(uncustomised) as WSS complies a ghosted page into an assembly DLL for processing.

But if you customise this page or open in SharePoint,  SharePoint safe mode don’t allow this and you would get error “Code blocks are not allowed in this file”.

You could force SharePoint to allow in-line scripts in customised pages by adding following to the web.config

<SharePoint>
  <SafeMode ... >
    <PageParserPaths>
      <PageParserPath
          VirtualPath="/Study/CustomPages/*"
          IncludeSubFolders="true"
          CompilationMode="Always"
          AllowServerSideScript="true" />
    </PageParserPaths>
  </SafeMode>
</SharePoint>

Note: You should avoid doing this as it compromise SharePoint security. In-Line scripts are not allowed in customised pages so that unwanted user could not write malicious code to hack the system.

0 comments: