我试图在SharePoint 2010中的aspx页面中使用C#代码。我不断收到“代码块不允许”错误。SharePoint 2010允许特定页面的代码块
位于(服务器)/SitePages/ajax.aspx我的aspx页面:(SharePoint Designer 2010中编辑,如果它事项)
<%@ Page Language="C#" %>
<script runat="server">
Response.Write("Hello world");
</script>
我说在C以下到web.config中:\ Program Files文件\ Common Files文件\ Microsoft共享\ Web服务器Extensions \ 14 \ CONFIG
<PageParserPath VirtualPath="/SitePages/ajax.aspx" CompilationMode="Always" AllowServerSideScript="true" />
在这里,在上下文中显示,我加入到web.config中的同一行:
<SharePoint>
<SafeMode
MaxControls = "200"
CallStack = "false"
DirectFileDependencies ="10"
TotalFileDependencies = "50"
AllowPageLevelTrace = "false"
>
<PageParserPaths>
<PageParserPath VirtualPath="/SitePages/ajax.aspx" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>
为什么我仍然得到“代码块”错误?是否有另一个安全开关?
(我知道自定义Web部件是首选的解决方案,但我不认为这会在这里就够了,因为返回值应该是JSON - 这是一个页面通过Ajax获得的数据命中。)
这当然是最佳做法的答案,但它是可能的(见德米特里的答案) – user1472408