httpcontext.current不支持自托管

发布于 01-19 10:46 字数 549 浏览 4 评论 0原文

当我通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天白云2025-01-26 10:46:38

HttpContext在自托管环境中不可用。 HttpContext 由 ASP.Net 管道设置,HttpContext 仅在 Web 托管模式下可用,在该模式下 HttpControllerHandler 创建请求。

httpcontext-shim 是在自托管 ASP.NET Web API 中工作的 HttpContext 的抽象。

PM> Install-Package HttpContextShim

参考: https://github.com/danielcrenna/vault/tree/master/ httpcontext-shim

HttpContextis 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.

PM> Install-Package HttpContextShim

Reference: https://github.com/danielcrenna/vault/tree/master/httpcontext-shim

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文