How to get rid of Event Viewer errors?

Error:
The description for Event ID ( 0 ) in Source ( Learning Management System ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event:

In registry:
1. Open regedit and go to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\Application\Learning Management System.
2. If ‘EventMessageFile’ is missing then the error above show is the event log. See the image below.

RegistryKey

RegistryKey

Code and solution :
The code below has ‘EventLog.CreateEventSource’ which creates ‘Learning Management System’ key under ‘HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\Application’ in registy and also create ‘EventMessageFile’ expandable string value with details below:
Value name:EventMessageFile
Value data: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\EventLogMessages.dll

If the ‘EventMessageFile’ string is missing it show the error message above. On my xp machine I do not see the above message because when I run the code it creates the ‘Learning Management System’ and EventMessageFile string. If you have manually created the key in the registry on the Windows 2003 server because you are getting security exception while the application trying to create the key, then you have to mannually create the EventMessageFile string with the above mention details.

//Check if the ATLAS web services working
 if (reqHTTPGetADFWebServices.StatusCode == 0)
 {
    //Check if the event log application exist
    if (System.Diagnostics.EventLog.Exists("Application"))
    {
       //Check if the event log source exist
       if (!System.Diagnostics.EventLog.SourceExists("Learning Management System"))
       {
          //Register the source                            
          EventLog.CreateEventSource("Learning Management System""Application");
          // The source is created.  Exit the application to allow it to be registered.                          
       }
 
   // Write an source, message and type entry to the event log.  
   System.Diagnostics.EventLog.WriteEntry("Learning Management System""FAILED:
 ADF web services are not available."EventLogEntryType.Error);                      
}

Resources:
Error Message When ASP.NET Application Tries to Write New EventSource in the EventLog

How to check whether the application is single sign on or form authentication from C# code?

Suppose you have a C# web application which need to run on a internal (inside network) and external (DMZ) web servers. These two application talks to the same database. The internal application need single sign on (SSO) and the external application is form authentication. Now in Visual studio you have one project for both these applications. Depending on the web.config’s configurations the application either do SSO or form authentication.

For SSO the web.config settings are,
<authentication mode="Windows"></authentication>

For form the web.config settings are,
<authentication mode="Forms">
<forms name="LegalAidLogin" loginUrl="~/login.aspx" defaultUrl="~/default.aspx" timeout="30" protection="All" enableCrossAppRedirects="true">
</forms>
</authentication>

Now, when you in login page which you have to need to check the authentication mode on page load, use the code below,

// Load web.config
System.Xml.XmlDocument config = new System.Xml.XmlDocument();
config.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
System.Xml.XmlNode node = config.SelectSingleNode(”//configuration/system.web/authentication”);

// Check the login mode for forgot your password
if (node.Attributes["mode"].Value == “Forms”)
{}

If you are already login in and you need to check the authentication mode use code below,

if (HttpContext.Current.User.Identity.AuthenticationType != “Forms”)
{}

Visual Studio 2010 Could not load file or assembly

Visual Studio build error: :
Error 15 Could not load file or assembly 'file:///C:\Documents and Settings\kumard\My Documents\Visual Studio 2010\Projects\LANSW.LMS\site\References\SwitchIT.DataAccess.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

Solution:

  • Right click on each *.dll file in Windows Explorer.
  • Uncheck “Read Only”.
  • Click “Unblock”.

If dll are stored in a network drive, move them locally and re-add your references.