博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
转:Code-blocks are not allowed in this file: Using Server-Side Code with SharePoint
阅读量:5167 次
发布时间:2019-06-13

本文共 2247 字,大约阅读时间需要 7 分钟。

Code-blocks are not allowed in this file: Using Server-Side Code with SharePoint

If you use the Microsoft Office SharePoint Designer to add a new page to your site, you will see that it looks just like any other ASP.NET page. Open up your site with the SharePoint Designer, and then go to the Pages folder. Right-click the Pages folder and choose New / ASPX. That will generate a new ASP.NET page with the following default template:

<%@ Page Language="C#" %>

<html dir="ltr">

<head id="Head1" runat="server">

<META name="WebPartPageExpansion" content="full">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Untitled 1</title>

</head>

<body>

<form id="form1" runat="server">

</form>

</body>

</html>

You can see this is the same ol' ASP.NET. There is a Page directive, and the familiar form element with the runat attribute set to "server". Yep, same ASP.NET code. The first thing I tried to do was to add some server-side code to my new page and see it actually work.

<script runat="server">

protected void Page_Load(object sender, EventArgs e)

{

form1.InnerHtml = "<h1>Hello</h1>";

}

</script>

When I hit F5, though, I got this error message:

"An error occurred during the processing of /Pages/test.aspx. Code blocks are not allowed in this file."

Hmm… yeah, code blocks are allowed in ASP.NET pages. What's going on? Oh yeah! SharePoint disables the ability to create server-side script by default, you have to turn it on. You do that in the web.config file, in the configuration/SharePoint/PageParserPaths configuration section:

<PageParserPaths>

  <PageParserPath VirtualPath="/pages/test.aspx" CompilationMode="Always" AllowServerSideScript="true" />

</PageParserPaths>

Success! Now, when I view the page in the browser, the page shows the Hello message as an H1 element instead of that error message about "code blocks are not allowed in this file", because we explicitly enabled code blocks in the web.config file.

A word of caution, here. The VirtualPath attribute accepts wildcards. Be cautious about allowing any ol' page to have server side script, you can restrain to a single page (as I did above) or only a subset of pages or directories.

转载于:https://www.cnblogs.com/wenjielee/archive/2010/12/29/1921178.html

你可能感兴趣的文章
前端学习网站
查看>>
Unity 的一些优化总结 (难度3 推荐4)
查看>>
使用resumable.js上传大文件(视频)兵转换flv格式
查看>>
在centos上安装mitsuba
查看>>
ToggleButton开关按钮的使用
查看>>
男人穿什么样比较容易追到白富美
查看>>
学习进度03
查看>>
假期周进度报告06
查看>>
shiro身份验证
查看>>
NOIP2013火柴排队
查看>>
对象的上转型对象 什么是面向对象
查看>>
用js来实现那些数据结构16(图02-图的遍历)
查看>>
【转】 如何使用Valgrind memcheck工具进行C/C++的内存泄漏检测
查看>>
Mysql基本操作小结
查看>>
Android开发进度04
查看>>
泛型Class<T>和 T. <T>
查看>>
Hibernate saveOrUpdate方法到底是怎么执行的?
查看>>
后端程序员之路 23、一个c++的api framework
查看>>
即时通信软件
查看>>
Tableau10.0学习随记-分组问题
查看>>