how does System.Web.HttpRequest::PathInfo work?

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)

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

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

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


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.

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.


I have just been trying to do a similar thing with Elmah.

My route was set up as follows:

var url = "admin/elmah.axd/{*pathInfo}"; var defaults = new RouteValueDictionary {{"pathInfo", string.Empty}}; var routeHandler = new ElmahHandler(); var route = new Route(url, defaults, routeHandler); RouteTable.Routes.Add(route);

But I too found that the pathinfo is always empty, so the stylesheet and additional paths didn't work. I managed to achieve my goal using reflection to call the underlying methods in the ErrorLogFactory.

private object InvokeMethod(string name, params object[] args) { var dynMethod = typeof(ErrorLogPageFactory).GetMethod(name, BindingFlags.Static | BindingFlags.NonPublic); return dynMethod.Invoke(null, args ); }

Then my handler looked like this

public class ElmahHandler : ErrorLogPageFactory, IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { var handler = InvokeMethod("FindHandler", requestContext.RouteData.Values["pathInfo"]) as IHttpHandler; if (handler == null) throw new HttpException(404, "Resource not found."); var num = (int)InvokeMethod("IsAuthorized", context); if (num != 0 && (num >= 0 || HttpRequestSecurity.IsLocal(context.Request) /*|| SecurityConfiguration.Default.AllowRemoteAccess*/)) { return handler; } //new ManifestResourceHandler("RemoteAccessError.htm", "text/html").ProcessRequest(context); HttpResponse response = context.Response; response.Status = "403 Forbidden"; response.End(); return null; } }

I had no need to get the ManifestResourceHandler working, so just commented it out, likewise for the allowRemoteAccess setting


  • main thread blocked on SCNetworkReachabilityGetFlags
  • Makefiles: Get .cpp from one directory and put the compiled .o in another directory
  • Advantage of find an object using Hibernate's @NaturalId
  • Excel 2007 Change colour of bars in a single series, based on another field
  • Pivot table calculated Field from count of values
  • Expand header row into multiple child rows
  • Picasso Taking time to load images
  • jquery validation - waiting for remote check to complete
  • Plotting densities in R
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • Scala multiline string placeholder
  • Does Mobilefirst provide a provision to access web services directly?
  • Breaking out column by groups in Pandas
  • Not able to aggregate on nested fields in elasticsearch
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • Time complexity of a program which involves multiple variables
  • Test if a set exists before trying to drop it
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Highlight one bar in a series in highcharts?
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • Get object from AWS S3 as a stream
  • Cross-Platform Protobuf Serialization
  • Incrementing object id automatically JS constructor (static method and variable)
  • Validaiting emails with Net.Mail MailAddress
  • Do I've to free mysql result after storing it?
  • Calling of Constructors in a Java
  • Comma separated Values
  • PHP: When would you need the self:: keyword?
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Error creating VM instance in Google Compute Engine
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • LevelDB C iterator
  • unknown Exception android
  • How can i traverse a binary tree from right to left in java?