Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Debugging ASP.NET application at run-time
Message
De
17/01/2009 10:54:08
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01374333
Message ID:
01374645
Vues:
13
>First, thank you for your help. I thought I did try the following line in my code:
>EventLog.CreateEventSource(source, logName);

You're welcome. But I left out the most important part, silly me (and obviously nobody tried it, otherwise I would have heard about it! <g>).

The CreateEventSource still needs to be run, which you tried yourself, but it needs to be done under some sort of valid authentication. The part that does that, in the code I posted, was left out. Sorry! I call a LogonUser() method, but I forgot to include that. Here it is:
// Using this api to get an accessToken of specific Windows User by its user name and password	
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static public extern bool LogonUser(string userName, string domain, string passWord, int logonType, int logonProvider, ref IntPtr accessToken);
Now it should work. As I said, this only needs to be run once.

~~Bonnie



>>Dmitry,
>>
>>The problem *is* a security issue. We use the event log also and have tried several different ways to get the Event Source created programmatically. We finally decided on a Web Service web method, which can just be accessed through IE.It only needs to be done once. Here's the web method:
>>
>>The line containing "Events.EventSources" is simply an Enum containing the names of EventSources we might use in our app. If you only have one, then you can just get rid of that whole foreach loop and just hardcode the name of your source in the if.
>>
>>
>>[WebMethod(Description = "Set server Event Log sources.")]
>>public string SetEventLogSources(string Username, string Password, string Domain)
>>{
>>	//This will keep track of the impersonation token
>>	const int LOGON_TYPE_INTERACTIVE = 2;
>>	const int LOGON_TYPE_PROVIDER_DEFAULT = 0;
>>	string logName = "Application";
>>	IntPtr userToken = IntPtr.Zero;
>>
>>	if (LogonUser(Username, Domain, Password, LOGON_TYPE_INTERACTIVE, LOGON_TYPE_PROVIDER_DEFAULT, ref userToken))
>>		{
>>		//Initialize user token 
>>		WindowsIdentity oIdentity = new WindowsIdentity(userToken);
>>		WindowsImpersonationContext oContext = oIdentity.Impersonate();
>>
>>		foreach (string source in Enum.GetNames(typeof(Events.EventSources)))
>>		{
>>			if (EventLog.SourceExists(source) == false)
>>				EventLog.CreateEventSource(source, logName);
>>		}
>>
>>		//Undo impersonation
>>		oContext.Undo();
>>
>>		return "Event source registration successful!";
>>	}
>>	else
>>	{
>>		return "Unable to process user credentials for event source registration.";
>>	}
>>}
>>
>>
>>~~Bonnie
>
>Bonnie,
>
>First, thank you for your help. I thought I did try the following line in my code:
>
>
>EventLog.CreateEventSource(source, logName);
>
>
>But not sure if I used the right values as parameters. I have made a point to find a good article on this topic to understand it better. I have solved my initial problem by creating a bunch of simple text files with messages. In the beginning I didn't think the ASP.NET would allow me to do it on the Server 2003; but it was no problem. As a side note, I was so upset with myself that after several hours of troubleshooting this problem, I found that the cause was missing letter "l" in one of the keys of WEB.CONFIG on the customer site. The good thing is that I learned something new and hopefully will learn more new stuff.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform