博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Difference between HttpContext.Request and Request
阅读量:7041 次
发布时间:2019-06-28

本文共 1212 字,大约阅读时间需要 4 分钟。

Well:

  • is a static property returning the current HttpContext for the thread
  • is an instance property returning the HttpRequest for the HttpContext you call it on
  • is an instance property in Page, returning the Request associated with the page you call it on (typically implicitly this)

So HttpContext.Current.Request will use both of the first two properties in order to get the request associated with the current thread. If you're in the thread dealing with a request, that's going to be the same as the Page.Request within the relevant page which is being rendered.

However, if your rendering kicks off a different thread, the code running in the other thread can still get at the Request via Page.Request (because it's just a normal property) but there'll be no HttpContext associated with the thread - so HttpContext.Current.Request wouldn't work.

EDIT: To respond to the edited question, in global.asax the Request property refers to , and is probably the best approach to use. HttpContext.Request won't work, because that's trying to access a static property as if it were an instance property. HttpContext.Current.Request should work, assuming the context has been associated with the thread by that point.

 

转载地址:http://juxal.baihongyu.com/

你可能感兴趣的文章
js 文件上传
查看>>
增强 DIR-505 硬件
查看>>
IT人生
查看>>
高并发系统之限流特技
查看>>
前端开发利器-SublimeText 之 插件篇
查看>>
边框的两种写法
查看>>
最全的2019当前可用的手机号码归属地查询api接口(精确到地市)
查看>>
jQuery 2.0 发布
查看>>
位图信息头BITMAPINFOHEADER
查看>>
Kubernetes应用部署工具-Helm2.7.2安装
查看>>
spring 系列教程二:HelloWorld实例
查看>>
Git删除远程仓库的最近一次错误提交
查看>>
PHP3 入门教程(极短篇)---要注意的地方
查看>>
Working with vectors
查看>>
VMware虚拟机共享主机无线网络联网的设置方法
查看>>
实现类似百度搜索结果的翻页效果
查看>>
微服务架构下的服务关联图
查看>>
The Nested Set Model
查看>>
Angular开发(五)-关于组件的基本认识
查看>>
计算两个经纬度之间的距离 单位(m)
查看>>