Search code examples
asp.netexceptionevent-logsystem.diagnostics

Security exception unhandled by user code


my code is here

 try
                {
                    db.Entry(object).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("MyEventSource", ex.StackTrace, EventLogEntryType.Warning);
                }

and I am getting error when I write ex to Event Log. Error is "Security exception unhandled by user code "


Solution

  • Add following configuration code to your web.config inside <system.web> tag.

    <identity impersonate="true" userName="UserName" password="123456789HI987654351"/>
    

    You need to set your system username and password and also set authentication mode windows.

    <system.web>
      <authentication mode="Windows"/>
      <identity impersonate="true" userName="yourUsername" password="Your password"/>
    </system.web>