Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't log exceptions when Request.Form contains XML #12

Closed
JustinFrye opened this issue Dec 20, 2013 · 2 comments
Closed

Can't log exceptions when Request.Form contains XML #12

JustinFrye opened this issue Dec 20, 2013 · 2 comments

Comments

@JustinFrye
Copy link

// Send exception to Rollbar
var client = new RollbarClient(lRollbarConfig);

client.SendException(aFilterContext.Exception, null, null, 
n => { n.Person.Username = remoteLogData.UsernameWithLoadId;
          n.Person.Id = remoteLogData.UsernameWithLoadId;

Getting the popular A potentially dangerous Request.Form value was detected from the client error because aFilterContext.HttpContext.Request.Form contains some XML, This is a huge buzz kill because almost all of our requests have XML in them, so we aren't seeing any of our server errors.

Any idea how we can get around this? Is my only option to html encode the Request.Form XML values on the client before they are even sent? We use MVC so we get around this in our requests by using ValidateInput(false) as seen here but you can see there are other solutions such as setting the request validation mode to 2.0.

@mroach
Copy link
Owner

mroach commented Dec 20, 2013

To be clear, you're getting this error on the client-side because the browser is posting XML and ASP.NET is rejecting the request, but you want RollbarSharp to pickup these events and report them?

Whenever you see that "potentially dangerous" error it usually means that you need to encode something on the client side before sending it to the server. So I think you're on the right track there with client-side encoding.

As for Rollbar reporting, I think the problem is that the ASP.NET normal processing pipeline stops short of where you'd be able to report to Rollbar. The solution for that might be to create an ASP.NET Health module. I could think about that...

@JustinFrye
Copy link
Author

Not exactly. I need zoom out a bit...

I knew there was an exception happening on the server during an ajax request but I didn't know why it wasn't being logged. To be more specific, it was a simple Object reference not set to an instance of an object error due to some variable being null. This error bubbled up to our server side exception handler, which of course, wants to report to Rollbar (see this code below). So, when I stepped through the code, I found that when it called client.SendException, the previously mentioned exception A potentially dangerous Request.Form value was detected from the client is thrown.

Does this make it more clear what is going on? I have "caught" a server side exception during an ajax request and I am trying to log it.

protected override void OnException(ExceptionContext aFilterContext)
      {
        try
        {
          // Set Rollbar Configuration for this error (application and environment)
          Configuration lRollbarConfig = new Configuration(remoteLogData.ServerAccessToken);
          lRollbarConfig.Environment = remoteLogData.Environment;

          var client = new RollbarClient(lRollbarConfig);

          // ERROR HAPPENS HERE, WHEN I CALL client.SendException
          client.SendException(aFilterContext.Exception, null, null, 
              n => { n.Person.Username = remoteLogData.UsernameWithLoadId;
                        n.Person.Id = remoteLogData.UsernameWithLoadId; 
                        n.Custom["RequestId"] = remoteLogData.RequestId;
          });
          ...

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

No branches or pull requests

3 participants