Scenario:
I was trying to put together a new UI with inline code. I designed it in Visual Studio as ASPX file and it worked without any issues. But when I moved the same page to SharePoint and accessed it, I got the following error
Error : An error occurred during the processing of /default.aspx. Code blocks are not allowed in this file.
Solution:
Short and simple , use code behind for all the custom pages, sharepoint doesn't allow code block ( ie. Eval and Bind functions ) for security reasons.
Its not like that you can never have a page with inline code, but its not recommended.
Also one more thing, if you really made the page work somehow with inline code, as soon as that page is touched by Designer, you are back to square with the same message. So dont try too hard on that.
Just-in-case you really want to make your inline code based page work.. you need to create a feature and use module tag in element.xml file to upload this file inspite of uploading it with browser or SharePoint Designer. Then it will not complain for code blocks.
:-)
Monday, January 26, 2009
Subscribe to:
Post Comments (Atom)
7 comments:
Hi,
I am facing the following problem:
I created site pages through features and having an inline code in the site page. I added the pageparser entry in the web.config and it worked fine. I opened the site page in SP designer and made some changes. When i refresh the page in SP site i am again getting the same err "code block are not allowed in this file". Is there any issues with opening site pages in SP designer. Awaiting for your valuable reply.
As I explained, you can certainly make Page Parser entries in web.config to make it work temporarily but I will not recommend that. Also as I mentioned any page with Inline code in it , when modified by SharePoint Designer will bring you back to the same error. So move all your code to Code Behind, you will never get that problem again. I have some blog entries to show the same. Search for Code Behind on my blog.
Hi Sandeep,
Thanks for your valuable reply. I will try with code behind logic.
can't we do like this?
http://mohammedfauzi.blogspot.com/2009/06/moss-code-blocks-are-not-allowed-in.html
This will work .. but its opening holes in security
Hi sandip i dont have Web.config access what can I do. pls explain u r approch in brief
#1: You can deploy pages with code behind using Sandbox Solution
#2 : you can use Jquery + Web service to do what u want to do :)
Post a Comment