本文介绍了System.Web.HttpRequest :: PathInfo如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解System.Web.HttpRequest的PathInfo属性及其设置方式.

I am trying to understand the PathInfo property of System.Web.HttpRequest and how it is set.

在下面的示例中为什么它为空?

Why would it be empty in the following example?

var p = new System.Web.HttpRequest("file.txt","http://file.com/files/file.txt","");
//PathInfo is always empty
return string.IsNullOrEmpty(p.PathInfo)

我试图通过调用Elmah.ErrorLogPageFactory :: ProcessRequest(HttpContext context)通过Nancyfx通过Elmah接口进行管道传输.

I am trying to pipe the Elmah interface through Nancyfx by invoking the Elmah.ErrorLogPageFactory::ProcessRequest(HttpContext context).

但是它不起作用,因为Elmah.ErrorLogPageFactory依赖于HttpRequest :: PathInfo来解析正确的IHttpHandler,并且PathInfo始终为空.

but it does not work because Elmah.ErrorLogPageFactory depends on HttpRequest::PathInfo to resolve the correct IHttpHandler and PathInfo is always empty.

如果有人花时间解释PathInfo的工作原理,我将不胜感激!

If someone would take the time explaining how PathInfo works I would be very grateful!

推荐答案

PathInfo属性是基于HttpRequest类的HttpContext私有变量计算的.没有官方方法来设置此HttpContext实例.这就是为什么每次手动创建HttpRequestHttpContext始终为null,因此PathInfo也使用空的原因.

The PathInfo property is calculated basing on HttpContext private variable of the HttpRequest class. There's no official way to set this HttpContext instance. That's why whenever you create the HttpRequest manually, the HttpContext is always null, therefore the PathInfo use empty also.

要获取与空字符串不同的内容,您需要使用由.NET框架创建的真实实例,而不是自己实例化.

To get something different from empty string you need to use a real instance, which is created by .NET framework to you, and not to instantiate it by yourself.

这篇关于System.Web.HttpRequest :: PathInfo如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 18:18