Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SharePoint 2010允许特定页面的代码块_C#_Sharepoint 2010_Codeblocks - Fatal编程技术网

C# SharePoint 2010允许特定页面的代码块

C# SharePoint 2010允许特定页面的代码块,c#,sharepoint-2010,codeblocks,C#,Sharepoint 2010,Codeblocks,我试图在SharePoint 2010的aspx页面中使用C代码。我不断得到的代码块都是不允许出错的 我的aspx页面位于server/SitePages/ajax.aspx:在SharePoint Designer 2010中编辑(如果有必要) <%@ Page Language="C#" %> <script runat="server"> Response.Write("Hello world"); </script> 我在C:\Program

我试图在SharePoint 2010的aspx页面中使用C代码。我不断得到的代码块都是不允许出错的

我的aspx页面位于server/SitePages/ajax.aspx:在SharePoint Designer 2010中编辑(如果有必要)

<%@ Page Language="C#" %>
<script runat="server">
    Response.Write("Hello world");
</script>
我在C:\Program Files\Common Files\Microsoft Shared\web Server Extensions\14\config的web.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点击以获取数据的页面。

当您将aspx页面上载到文档库时,这就是您在使用SharePoint Designer时所做的,即aspx页面不能有内联代码块,也不能有代码隐藏。这主要是一种安全机制。它可以防止任何老用户上载包含恶意内容的aspx页面,这些恶意内容将在您的服务器上以完全权限执行,并且还可以向可能的任何用户提供内容

对于要执行代码的aspx页面,需要将其编译成WSP并部署到服务器上的GAC。当您这样做时,您可以使用内联代码块,或者更好的是,使用带有代码隐藏的aspx页面。要将该页面发布到站点,您需要在VisualStudio中将该项目编译成WSP,通过以足够的权限登录到计算机将其部署到服务器,然后添加并部署代码。这确保了非开发人员不能将可执行代码上传到您的站点


最后,还有一点与此无关,因为您实际上不想显示页面,而只想显示JSON内容,所以您可能根本不应该使用aspx页面,尽管您可以。您可能只需要创建一个HTTP处理程序或一个web服务来写出适当的内容。

我想,您必须在位于C:\inetpub\wwwroot\wss\VirtualDirectories[application folder]\web.config的web应用程序web.config中定义PageParserPath元素。

这肯定是最佳实践答案,但有可能看到德米特里的答案