Skip to content
This repository has been archived by the owner on Dec 8, 2018. It is now read-only.

Finding Original RequestUri with IExceptionHandlerFeature #292

Closed
Tratcher opened this issue May 13, 2016 · 4 comments
Closed

Finding Original RequestUri with IExceptionHandlerFeature #292

Tratcher opened this issue May 13, 2016 · 4 comments

Comments

@Tratcher
Copy link
Member

From @shawnwildermuth on May 12, 2016 19:42

I'm trying to log the request URI when an exception is thrown. Logging is too abstracted out to do it so I thought that IHttpRequestFeature was my trick. Here's what I'm trying, please let me know if I'm way off the right track:

First I'm using an exception page:

app.UseExceptionPage("/Exception");

This logs the exception, but just the bare exception, no state of the request.

So, inside the Action for /Exception, I'm doing this:

    [HttpGet("Exception")]
    public IActionResult Exception()
    {
      var exception = HttpContext.Features.Get<IExceptionHandlerFeature>();
      var request = HttpContext.Features.Get<IHttpRequestFeature>();

      if (exception != null && request != null)
      {
        var originalPath = request.Path;
        // I could cast the request object to a Frame to get at the information, but that feels dirty

        // Manually logging the information
      }

      return View();
    }

Copied from original issue: aspnet/HttpAbstractions#630

@Tratcher
Copy link
Member Author

We should add the original path to IExceptionHandlerFeature here:

@Tratcher Tratcher changed the title Finding Original RequestUri with IHttpRequestFeature Finding Original RequestUri with IExceptionHandlerFeature May 13, 2016
@Eilon Eilon added this to the 1.0.1 milestone May 18, 2016
@bedwar2
Copy link

bedwar2 commented Jun 16, 2016

When a 403 is encountered I'd like to get the RequestURI to log what URL user attempted. Shouldn't ReuestURI be on the IHTTPRequestFeature in that case as well? I see the original request was for it to be on IHttpRequestFeature. I still think it should be there. I use app.UseStatusCodePagesWithReExecute.

@Tratcher
Copy link
Member Author

@Eilon are the versioning guildlines ready for v1.1? Do they allow adding properties to feature interfaces?

@Eilon
Copy link
Member

Eilon commented Jun 17, 2016

@Tratcher working on the guidelines. Changing an interface in any way is a breaking change that we would not make. We can add a new interface, though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants