SharePoint 2007 版本开始支持 .aspx 嵌入内联代码,但此项功能默认是关闭,可以再 web.config 的 SharePoint/SafeMode/PageParserPaths 配置节进行配置,如
<PageParserPaths> <PageParserPath VirtualPath="/pages/hello.aspx" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/></PageParserPaths>
还可以用通配符
<PageParserPaths> <PageParserPath VirtualPath="/pages/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/></PageParserPaths>
其中 CompilationMode 可用值包括:Always The page should always be compiled (default value) Auto ASP.NET will not compile the page, if possible. Never The page or control should never be dynamically compiled.
基于安全的考虑,最好不要对所有文件开启此项功能。因为任何具有修改页面的权限的用户有可能天健恶意代码。
今天,要在人家原来的系统上加个独立的功能页面,没有原代码的,所以只能把c#的后台代码写在aspx页面上,但是各控件的事件等让我犯难了,要怎么写呢?
原来,其实跟写后台代码一样写,把设计器生成代码也copy过去,委托什么的一样写,还挺方便的,如下面:
<script language="c#" runat="server">
#region Page_Load private void Page_Load(object sender, System.EventArgs e) {
……
if(!Page.IsPostBack) {……}
} #endregion
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click); this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); this.FSDataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.FSDataGrid1_ItemDataBound); this.Load += new System.EventHandler(this.Page_Load);
} #endregion
private void btnAdd_Click(object sender, System.EventArgs e) {……}
private void btnSearch_Click(object sender, System.EventArgs e) {……}
</script>