Sitecore.Context.Item 回发时为 NULL
我继承了一个 sitecore 实现,并且一直在尝试调试会员表单。会员页面包含一个会员子布局,其中包含一个简单的表单(名字、姓氏、地址……)。当我在本地计算机上调试时,我填写表单并单击提交。页面回发,一旦基本布局被命中,Sitecore.Context.Item
就为 NULL
。 有趣的是,如果我在 Sitecore 中预览页面,当我回发时一切正常,这让我相信这只是我的 web.config 或其他配置文件中的一些内部设置的问题。
以下是 PREVIEW 模式和常规模式下页面首次点击和回发时的一些变量内容:
首次点击(预览模式)
Sitecore.Context
.Data.RawUrl = /?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Database = master
.Item,Database = master
.Item.Id = {2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB}
.Item.Name = Website_Membership
.RawUrl = /?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Request.ItemPath = /sitecore/content/home/
回发(预览模式)
Sitecore.Context
.Data.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Database = master
.Item,Database = master
.Item.Id = {2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB}
.Item.Name = Website_Membership
.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Request.ItemPath = /sitecore/content/home/sites/cms/layouts/membership layout
首次点击(常规模式)
Sitecore.Context
.Data.RawUrl = /SomePath/Website_Membership.aspx
.Database = web
.Item,Database = web
.Item.Id = {2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB}
.Item.Name = Website_Membership
.RawUrl = /SomePath/Website_Membership.aspx
.Request.ItemPath = /sitecore/content/home/somePath/website_membership
回发(常规模式)
Sitecore.Context
.Data.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx
.Database = web
.Item = NULL
.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx
.Request.ItemPath = /sitecore/content/home/sites/cms/layouts/membership layout
有没有人以前经历过类似的事情和/或您能想到发生这种情况的任何原因吗?
编辑: 在 sdn.sitecore 论坛 Kevin Buckley 上:
我正在考虑控制适配器 缺少“表单.浏览器”。它应该 位于 app_browsers 文件夹中。
我只是想添加一条注释。 app_browsers 文件夹中缺少这些文件,但几天前我通过从干净的 sitecore 安装中复制它们来手动添加它们。这似乎没有帮助。
I am inheriting a sitecore implementation and I have been trying to debug a membership form. The membership page contains a membership sublayout that contains a simple form (first, last, address,...). When I am debugging on my local machine, I fill the form and click submit. The page posts back and as soon as the base layout is hit, the Sitecore.Context.Item
is NULL
.
The interesting part is that if I PREVIEW the page within Sitecore, when I postback everything works fine, which makes me believe that it's just a matter of some internal settings in my web.config or some other configuration file.
Here are the content of some variables on the first hit of the page and on the postback in both PREVIEW mode and regular mode:
first hit (preview mode)
Sitecore.Context
.Data.RawUrl = /?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Database = master
.Item,Database = master
.Item.Id = {2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB}
.Item.Name = Website_Membership
.RawUrl = /?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Request.ItemPath = /sitecore/content/home/
Postback (preview mode)
Sitecore.Context
.Data.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Database = master
.Item,Database = master
.Item.Id = {2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB}
.Item.Name = Website_Membership
.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx?sc_itemid=%7b2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB%7d&sc_mode=preview&sc_lang=en
.Request.ItemPath = /sitecore/content/home/sites/cms/layouts/membership layout
first hit (regular mode)
Sitecore.Context
.Data.RawUrl = /SomePath/Website_Membership.aspx
.Database = web
.Item,Database = web
.Item.Id = {2A58FFA4-D16A-4EAB-8298-9398ACFDDEFB}
.Item.Name = Website_Membership
.RawUrl = /SomePath/Website_Membership.aspx
.Request.ItemPath = /sitecore/content/home/somePath/website_membership
postback (regular mode)
Sitecore.Context
.Data.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx
.Database = web
.Item = NULL
.RawUrl = /Sites/CMS/Layouts/Membership Layout.aspx
.Request.ItemPath = /sitecore/content/home/sites/cms/layouts/membership layout
Has anyone experienced something like this before and/or can you think of any reason for this to happen?
EDIT:
On the sdn.sitecore forum Kevin Buckley:
I'm thinking the control adapter
'form.browser' is missing. It should
be in the app_browsers folder.
I just want to add a note in regards. The files were missing from the app_browsers folder BUT I had added them manually few days ago by copying them from a clean sitecore installation. That didn't seem to help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您似乎正在回发到 Membership layout.aspx,因此您的上下文项为空,因为路径 Membership Layout.aspx 不与项目关联。
你如何控制回发网址?默认情况下,您遇到的问题不会发生。我不记得具体在哪里,但某些方法或属性将返回 sitecore 项目布局文件而不是 url,正如您通常期望的那样。您可能正在使用 server.transfer 吗?正常的回发将默认为相同的 url ,你这样做吗?
You appear to be posting back to Membership layout.aspx hence your context item is null, as the path Membership Layout.aspx does not correlate to an item.
How are you controlling the postback url? By default the problem you have doesn't happen. I can't remember where specifically but some methods or properties will return the sitecore items layout file rather than the url, as you may normally expect. Are you using server.transfer maybe ? A a normal postback will default to the same url , are you doing this?
今天,在升级到最新的 Sitecore 6.5 rev 111123 后,我在回发后遇到了同样的问题 Sitecore.Context.Item == null
事实证明问题开始出现,因为 App_Browsers\Form .browser 文件在升级过程中被删除。
当我恢复它时,这个问题就消失了。
希望这会有所帮助。
I had the same problem today with Sitecore.Context.Item == null after postback, after upgrading to the latest Sitecore 6.5 rev 111123
And it turned out the problem started to appear because App_Browsers\Form.browser file was removed during upgrade.
When I restored it back this issue disappeared.
Hope this will be helpful.
检查 web.config 中的
部分;在我看来,您似乎指向了错误的数据库,请检查您正在处理的
是否使用 Master 或 Web。这可以解释为什么它在预览中运行良好。Check the
<sites>
section in web.config; sounds to me like you're pointing at the wrong database, check to see if the<site>
you're working on is using Master or Web. That may explain why it works fine in Preview.更新到当前推荐的版本 - Sitecore 6.4.1 后,我遇到了同样的问题。
在我的情况下,正如您所看到的,结构将我的主要布局作为回发操作 - 这解释了我在前端回发的问题,而在 Sitecore 预览中一切都很好。
我通过在 MainLayout 中添加 action=# 纠正了这个问题
I've ran in the same issue, after update to currently recommended version - Sitecore 6.4.1.
In my situation, structure of , as you could see, have had my main layout as action for postback - and this explained my problem with Postbacks on frontend, while in Sitecore preview everything was fine.
I rectified this issue by adding action=# in my MainLayout