asp.net – 如何在Sitecore中以编程方式创建项目
发布时间:2020-12-16 09:17:28 所属栏目:asp.Net 来源:网络整理
导读:在内容树中,结构如下 Home -England -France -Germany 有一个子布局(CommentsForm.ascx),用于所有3个页面.当用户浏览“法国”并提交评论时,“评论”项目应保存在“法国”下,依此类推. 在这种情况下,父项(必须在其下创建新项)是动态的.那么,在这种情况下如何
在内容树中,结构如下
Home -England -France -Germany 有一个子布局(CommentsForm.ascx),用于所有3个页面.当用户浏览“法国”并提交评论时,“评论”项目应保存在“法国”下,依此类推. 在这种情况下,父项(必须在其下创建新项)是动态的.那么,在这种情况下如何获取父项.它是否正确? protected void btnSubmit_Click(object sender,EventArgs e) { Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = Sitecore.Context.Item; string name = "Comment_" + Sitecore.DateUtil.IsoNow; TemplateItem template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment"); using (new SecurityDisabler()) { //how to go about here?? //newItem["Author"] = txtAuthor.text; //newItem["CommentText"] = txtComments.Text; //parentItem.Add("name",template); } } 解决方法
您可以在生产中使用UserSwitcher更安全,但您也可以使用SecurityDisabler(newSecurityDisabler()){}
编辑和重命名必须在Editing.BeginEdit()事务中进行 Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = Sitecore.Context.Item; string name = "Comment_" + Sitecore.DateUtil.IsoNow; var template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment"); using (new Sitecore.SecurityModel.SecurityDisabler()) { try { Item newItem = parentItem.Add("Name",template); if (newItem!=null) { newItem.Editing.BeginEdit(); newItem["Author"] = txtAuthor.text; newItem["CommentText"] = txtComments.Text; newItem.Editing.EndEdit(); } } catch { newItem.Editing.CancelEdit(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 编程控制输出缓存 – 根据参数值禁用或启用缓存
- 为什么我需要在ASP.NET控件上调用处理?
- 我可以在同一解决方案中拥有多个ASP.Net网站吗?
- asp.net-mvc – 在.aspx上获得MVC Razor青睐.cshtml
- asp.net – OData和区分大小写
- asp.net – web.config转换未在VS2010中显示
- asp.net-mvc – 应该在ASP.NET MVC应用程序中缓存发生在哪里
- asp.net-mvc – ASP.NET MVC自定义错误页面(StatusCode 404
- ASP.Net负载均衡
- 什么是使用aspnet_compiler.exe预编译ASP.NET项目的优势?
推荐文章
站长推荐
- asp.net-mvc-4 – Cshtml无法解析引用
- asp.net-mvc – ASP.NET MVC模型/ ViewModel验证
- entity-framework – 如何将OData查询与DTO映射到
- asp.net – 我什么时候真的需要InamingContainer
- ASP.NET MVC与Web客户端软件工厂(WCSF)
- asp.net – 获取特定的会员提供商
- 如何获取ASP.NET C#中请求的文件的MIME类型?
- 在ASP.NET中,什么决定了HostingEnvironment.IsDe
- asp.net – System.Linq.Dynamic不支持OrderByDe
- web项目自定义路由_实现静态资源URL控制
热点阅读