Sitecore.Context.Item NULL on postback
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/CM开发者_如何学编程S/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.
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?
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.
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.
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
精彩评论