无法通过 API 访问 Sitecore 项目字段
我已向现有数据模板添加了一个包含几个新字段的新部分。当以普通用户帐户登录时,这些字段会正确显示。
但是,当使用 API 访问字段时,item.Fields["FieldName"] 始终返回 NULL。
我尝试过的事情:
- 发布项目和相应的数据模板
- 授予“每个人”对字段(和字段部分)的显式读取访问权限。
- 确认我的开发实例指向正确的数据库
- 调试显示我的两个新字段不在项目的 Fields 集合中。
我还执行了 iisreset,以防万一某些内容被缓存在某处。任何帮助将不胜感激。
I've added a new section containing a couple of new fields to an existing data template. The fields appear correctly when logged in as a normal user account.
However when accessing the fields using the API, item.Fields["FieldName"] always returns NULL.
Things I've tried:
- Publishing both the item and the corresponding data template
- Granting "Everyone" explicit read access to the fields (and field section).
- Confirmed that my dev instance is pointed to the correct database
- Debugging shows that my two new fields are not in the item's Fields collection.
I've also executed an iisreset, just in case something was cached somewhere. Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在访问该字段之前尝试调用 item.Fields.ReadAll() 。
Try calling item.Fields.ReadAll() before accessing the field.
您是否从同一个 sitecore 实例进行发布和开发?我见过开发人员对这个 b/c 感到沮丧,他们从开发服务器发布,然后在本地开发箱上查找该字段,该开发箱仍然缓存了模板的旧副本。在这种情况下,在开发服务器上发布不会清除本地缓存。
Are you publishing and developing from the same sitecore instance? i've seen developers get frustrated by this b/c they are publishing from say, a development server, then looking for the field on their local dev box, which still has an old copy of the template cached. publishing on the dev server wouldn't clear the local cache in that case.