Friday, May 15, 2009

SqlDataSource is not allowed on this page

Scenario:
One of my friend was working on a new Application page and used SQLDataSource. It works fine when you access the page in ASP.Net Context but when it was moved to SharePoint context , he got the following error

Error : SqlDataSource is not allowed on this page

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. Mostly SQLDataSource control uses lot of inline code blocks.

Its not like that you can never have a page with inline code, but its not recommended. You can use SQLDataSource control , if all the binding's are done in code-behind and not in ASPX itself.

Also one more observation, if you really made the page with inline code work somehow, as soon as that page is touched by Designer for any reason, you are back to square with the same message. So dont try too hard on using inline code.

Why microsoft made it so hard ?
Because sometime server security is more important that Developer's comfort.

:-)

2 comments:

Anonymous,  May 31, 2009 at 1:13 AM  

But I thought application pages don't have any security restrictions - also they cannot be customized.

Sandeep May 31, 2009 at 9:17 AM  

They can be secured for a particular site collection or site by putting a small condition. Also they can be customized. I have many articles blogged..check them out