惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Webroot Blog
Webroot Blog
U
Unit 42
A
About on SuperTechFans
宝玉的分享
宝玉的分享
月光博客
月光博客
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Securelist
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
B
Blog
I
Intezer
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
V
V2EX
L
LangChain Blog
AI
AI
G
GRAHAM CLULEY
T
Tor Project blog
人人都是产品经理
人人都是产品经理
D
Docker
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
I
InfoQ
Y
Y Combinator Blog
C
Comments on: Blog
GbyAI
GbyAI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
H
Help Net Security
Vercel News
Vercel News
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿

博客园 - Jason Li 2011

Maven - import a web project into eclipse [分享] 兰迪·波许教授的最后一课[PDF/PPT/AVI] 转:Controlling Access to Members of a Class 转:退火算法 Simulate Anneal Arithmetic (SAA,模拟退火算法) Scrum in practise 转:MOSS 2007 and Code Access Security 转:CollaDec FriendlyQuery类库(beta)说明 转:MOSS站点的迁移(备份还原) 转:MOSS漫游(3):说说MOSS中的母版页 转:关于MOSS 2007的Content Types 转:Best Practices: Common Coding Issues When Using the SharePoint Object Model 转:Best Practices: Using Disposable Windows SharePoint Services Objects 转:Free the SPWeb 转:将你的Asp.NET应用程序嵌入到SharePoint Duff International Sites 项目总结 转:ASP.NET Web Services or .NET Remoting: How to Choose 转:类与结构的差别 转:SharePoint Server 2007 页面模型 转:MOSS 2007基础:WSS 3.0 中的母版页(Master Pages)和内容页(Content Pages) 转:How to: Create a Minimal Master Page
转:Code-blocks are not allowed in this file: Using Server-Side Code with SharePoint
Jason Li 2011 · 2010-12-29 · via 博客园 - Jason Li 2011

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.

posted on 2010-12-29 22:35  Jason Li 2011  阅读(522)  评论()    收藏  举报