-1

I'm trying to add Elmah logging to a webservice. The user gets authenticated to confirm that they are a valid user, but then they're never truly logged in. Because of this, when an error is thrown and recorded by ELMAH, the username is always blank. It would be helpful to be able to populate that value programmatically, yet I can't seem to find any way to do this.

My code is pretty simple:

public static void Add(Exception ex)
{
    try
    {
        ErrorSignal.FromCurrentContext().Raise(ex);
    }
    catch (Exception ex2)
    {
        throw ex2;
    }
}

I can't seem to find a way to create a custom exception where we specify the username.

oleksii
  • 35,458
  • 16
  • 93
  • 163
Cyfer13
  • 369
  • 7
  • 17
  • 1
    Just out of curiosity - why do you authenticate the users if you don't need to log them in? – Ilya Kogan Jan 05 '12 at 22:14
  • It's a web service, so we need to ensure that the user has the ability to use the web service and then need to log them in the database, but we don't need to do anything beyond that. It's possible that I can log the user in, but that would involve me rewriting a bunch of code so that the right information is passed to my exception. Was hoping to avoid that. – Cyfer13 Jan 05 '12 at 22:27
  • Where is the code where you authenticate the user you should be able to store the user name or domain user name once authenticated.. your code example doesn't really help much here sorry... – MethodMan Jan 05 '12 at 22:33

1 Answers1

0

If you can, I suggest run the web service as an impersonated user that has the appropriate authorities. This will depend, of course, on exactly how your users are authenticating, but it is an option.

Here's how we do this (added to the web service's web.config):

<identity impersonate="true" userName="registry:HKLM\Software\OurApp\ASPNET_SETREG,userName" password="registry:HKLM\Software\OurApp\ASPNET_SETREG,password"/>

We use the aspnet_setreg utility to record the domain user name and password in the registry and this user is then responsible for all database interaction, etc.

competent_tech
  • 44,465
  • 11
  • 90
  • 113