ASP.NET - Setting user by using system.webServer configuration

dannyyy

Posted on
Jul 07 2014

Hi,

I've integrated raygun.io with the system.webServer configuration within web.config. Now I want to add add a certain point in my application to set the (temporary) logged in user.

I tried this by just adding this code in my authentication method:

var raygunClient = new RaygunClient();
raygunClient.User = user.LoginName;

But occurred errors don't contains the username. Is this kind of configuration only possible if send the exception in the Application_Exception global event?

Or have I to set the API-Key again? Submitting anything with the send() methods is not useful because at that point of time because there is no exception at the moment ;)

Kind regards, Danny


Jason Fauchelle

Raygun

Posted on
Jul 08 2014

Hello Danny

Thanks for getting in touch about this. I'm guessing you're using the Raygun http module approach to cause Raygun4Net to automatically listen for unhandled exceptions and then send them for you. If so, here is how to set the User:

On your HttpApplication class, implement the IRaygunApplication interface. This will have a single method called GenerateRaygunClient. In this method, create a new instance of RaygunClient and set the User or UserInfo properties to whatever you need. Then return the RaygunClient instance, and that's all.

Now when unhandled exceptions are detected by the module, your GenerateRaygunClient method will be called so that your custom RaygunClient instance will be used to send the exception. GenerateRaygunClient is called for every exception which means that you can change the User or UserInfo properties if ever necessary.

If anything I've mentioned here seems to be missing, make sure to grab the latest version of Raygun4Net from NuGet or GitHub. Note that version 3 has a couple of small breaking changes which you can read about here: https://raygun.io/blog/2014/06/raygun4net-3-0/

Please let me know if you have questions about any of this :)

-Jason Fauchelle


dannyyy

Posted on
Jul 08 2014

Thank you very much. It was exactly what I was looking for.


Reply