httprequestbase request.item是怎么填写的?
我正在尝试测试一些使用 Request.Item("key") 的代码,但我找不到填写此属性的方法,因为它是只读的。我正在模拟 httpcontext 并已填写查询字符串、cookie、表单和 ServerVariables 集合,但在调试期间 Request.Item 集合每次都不会返回任何内容。我听说这可能是保存顺序的问题。感谢您的帮助,尼克
编辑: 所以我被告知搜索顺序可能是问题所在,但由于它们都已填写,所以我不相信这就是问题所在。 这是该想法的链接: HttpRequest 索引器的搜索顺序
I am attempting to test some code that uses Request.Item("key") but I can not find a way to fill out this property because it is read-only. I am mocking out the httpcontext and have gotten the querystring, cookies, form, and ServerVariables collections filled out, but during debug the Request.Item collection returns nothing everytime. I heard somewhere that it may be a save order issue. Thanks for any help, Nick
Edit:
So the Search Order was what I was told might be the issue, but since they are all filled out, I'm not convinced this is the issue.
Here is a link to that idea:
Search order of HttpRequest indexer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过覆盖继承自 httprequestbase 的 Request 类中的项目集合解决了问题。它在继承自 httpsessionbase 的 Session 类中被重写,但仅覆盖 Session.Items,而不覆盖 Request.Items
Issue was fixed by overriding the items collection in a Request class inheriting from httprequestbase. It was overridden in the Session class inheriting from httpsessionbase but that only covered Session.Items, not Request.Items