Posted by: wming | July 16, 2008

Enable Sharepoint server side script

By default, Sharepoint does not allow server side script for security reason. To get around this, you can modify your web.config to specify which page(s) you allow server side script. For example, you can add following code to your Sharepoint application web.config. ( I am using /en-ca/pages/* as example )

      <PageParserPaths>
        <PageParserPath VirtualPath=”/en-ca/pages/*” CompilationMode=”Always” AllowServerSideScript=”true” />
      </PageParserPaths>

I found this is very useful during development if you are using in-line script for your aspx pages. Let’s say you have a SP project including some customrized aspx pages. You’ve created feature and a wsp file to install in your Sharepoint. Now you noticed you have to do some change to the in-line script of the aspx file. Of course, you could re-deploy the entire wsp again, but as a developer, you don’t want do this because most likely you have to modify the aspx again and again :-)…Following is the steps I am using

  1. Load aspx pages from Sharepoint UI and publish it
  2. Reset IIS
  3. Load this aspx page from your browser

Sharepoint will give you error message saying server script is not allowed. OK, that’s fine, modify web.config add <PageParserPaths> and reload the page. Yeah, everything is working and you can see your changes.

Someting you should also know

  1. It is better using code behind for the aspx pages in your SP project. By using code behind, when you change any logic of your aspx pages, you only rep-deploy dlls, not the page itself. You don’t need modify web.config.
  2. Why this does not happen before you change and load the aspx page to the SP? That page also contains script, but SP did not give any error at that time. I will explain this in my next post “Sharepoint ghost”

Leave a response

Your response:

Categories