httpcontext.current不支持自托管
当我通过IIS安装应用程序时,安装成功,并且在进行自我托管安装时会失败。当调试发现httpcontext.current始终以自我托管为单位,并且密码永远不会被解密。
if (HttpContext.Current != null)
{
var request = HttpContext.Current.Request;
if (request.PathInfo.Equals("/api/login"))
{
password = Decrypt(password);
}
}
HTTPContext.Current是否有其他选择,以便它支持IIS和自托管安装?任何人都可以hlep!
注意:我尝试了httpcontextshim并修改了我的代码,但仍面临同一问题。还必须添加什么?
using HttpContext = HttpContextShim.HttpContext;
if (HttpContext.Current != null)
{
password = Decrypt(password);
}
When I am installing my application through IIS the installation is successful and when doing a SelfHosting installation, it fails. When debugging found that HttpContext.Current is always coming as null for Self-hosting and the password is never getting decrypted.
if (HttpContext.Current != null)
{
var request = HttpContext.Current.Request;
if (request.PathInfo.Equals("/api/login"))
{
password = Decrypt(password);
}
}
Is there any alternative for HttpContext.Current so that it supports for both IIS and Self hosting installation? Can anyone please hlep!
Note: I tried HttpContextShim and modified my code but still facing the same issue. What more has to be added?
using HttpContext = HttpContextShim.HttpContext;
if (HttpContext.Current != null)
{
password = Decrypt(password);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

HttpContext
在自托管环境中不可用。HttpContext
由 ASP.Net 管道设置,HttpContext
仅在 Web 托管模式下可用,在该模式下 HttpControllerHandler 创建请求。httpcontext-shim
是在自托管 ASP.NET Web API 中工作的 HttpContext 的抽象。参考: https://github.com/danielcrenna/vault/tree/master/ httpcontext-shim
HttpContext
is not available in a self-hosted environment.HttpContext
is set by the ASP.Net pipeline,HttpContext
is only available in the Web-Hosting mode, in which the HttpControllerHandler creates the request.httpcontext-shim
is An abstraction for HttpContext that works in self-hosted ASP.NET Web API.Reference: https://github.com/danielcrenna/vault/tree/master/httpcontext-shim