-1

I want to develop a console application using C# which gets the IIS Application Pool status information,whether its running or stopped.For this I referred check the status of IIS Application Pool which matches my requirement.

Can someone please clarify what is the purpose of Directoryentry class according to the above code?

Any help is appreciated.

Thankyou.

Jandi
  • 11
  • 5
  • BTW The referred code is using `ConfigurationManager` class which does **not** work with `appsettings.json` or any JSON files. – Sir Rufo Aug 01 '21 at 06:56
  • Does this answer your question? [How to fix the errors,name 'Children' does not exist in the current context. and the modifier 'new' is not valid for this item in c#](https://stackoverflow.com/questions/68604799/how-to-fix-the-errors-name-children-does-not-exist-in-the-current-context-and) – Progman Aug 01 '21 at 07:15

1 Answers1

0

The Directoryentry class is used here to get IIS application pools and you need to pass username and password to access them.

These required username and password need to be specified in "appsettings.json" file.

Abhay Desai
  • 143
  • 1
  • 8
  • I updated the question including the Appsettings.json file.Is that correct?Then what about the servername?How do I have to include it?As in program.cs file it is as " string ServerName = DT.Rows[i]["ServerName"].ToString().Trim();" – Jandi Aug 01 '21 at 05:48
  • There could be multiple options for you to save this kind of configuration settings, You can either save them in your "AppSettings" (which is less secure way as anyone who has got access to your "AppSettings" file can read your username and password) or save all your settings in a database (more secure way) or save all your settings as Environment Variables. The code which you are referring to, is getting Servername from a database table. – Abhay Desai Aug 01 '21 at 06:12
  • then if I want to save and access through "Appsettings" then how do I have to change my program.cs class.Iam new to C#,Iam bit confused and lost. – Jandi Aug 01 '21 at 06:32
  • If you want to use servername from your "AppSettings" file, then you can use similar kind of code line to read it's value from "AppSettings" file, the way it is doing now for username and password. * { "AppSettings": { "User": "value of your UserName", "Pass": "value of your Password", "Server": "value of your ServerName" } }* **Progra.cs file** *string UName = ConfigurationManager.AppSettings["User"];* *string Pwd = ConfigurationManager.AppSettings["Pass"];* *string ServerName = ConfigurationManager.AppSettings["Server"];* – Abhay Desai Aug 01 '21 at 06:49
  • I tried this way,but it passes a null value to the program.cs file,instead of the value stored in the appsettings.I included my full code here.Can you please let me know what is wrong in it?https://stackoverflow.com/questions/68608758/how-to-access-the-username-and-password-from-appsettings-file-to-program-cs-in-c – Jandi Aug 01 '21 at 08:39