Get role list from Web.Config


var res = new List<string>();
var conf = WebConfigurationManager.GetSection("system.web/authorization");
if (conf != null)
{
    var sec = (AuthorizationSection)conf;
    foreach (AuthorizationRule r in sec.Rules)
    {
        if (r.Action == AuthorizationRuleAction.Allow)
        {
            var p = r.ElementInformation.Properties["roles"];
            if (p != null)
            {
                if (p.ValueOrigin != PropertyValueOrigin.Inherited)
                {
                    string val = p.Value.ToString();
                    if (!string.IsNullOrEmpty(val))
                    {
                        string[] roles = val.Split(',');
                        foreach (string roleStr in roles)
                        {
                            string roleVal = roleStr.Trim();
                            if (roleVal != string.Empty)
                            {
                                res.Add(roleVal);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
}

SQL Express DB performance – auto-close evil

A quote from the original post:

By default, Express Edition creates databases with the Auto Close option enabled. This option allows SQL Server to close the physical operating system files for the database when all connections to the database are closed. The advantage here is that individual workstation installations can have database files copied around as easily as document files. This is not so advantageous in a server setup, as the overhead of opening the files and starting up the database can cause poor response times.

To check this setting for an individual database, right click the database in Management Studio, choose Properties, go to the Options page, and verify the state of the Auto Close option (it should be at the top of the list). You’ll almost certainly want to set this to False for every database on a dedicated server, with the possible exception of extremely seldom used databases.

See the original post here.

How to Run PHP on Vista

After googling I found few useful links:

Great – I got running PHP on Vista Ultimate along ASPX in single Web Site by configuring as FastCGI module.

About second option (ISAPI). PHP 5 doesn’t contain such php5isapi.dll described in configuration. I suppose that it’s mentioned only for older versions of PHP.

Specify to Run Server Garbage Collection (gcServer)

To enable Garbage Collector to work in server mode put follwing section in config:

<runtime>
  <gcServer enabled="true" />
</runtime>

When to use:

  • On computers with more Ā than two cores.
  • You have multithreaded serviceĀ not hosted in IIS.

Typical candidate: self-hosted WCF service.
This option improves service performance and consumes more memory.

For details see:

Encrupt/Protect Custom Configuration Section

Illustrates how to encrypt custom configuration section in the service OnStart event:

protected override void OnStart(string[] args)
{
	try
	{			    
		string sectionName = "SectionNameToSecure";
		
		Configuration config = 
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
		ConfigurationSection section = config.GetSection(sectionName);
		if (!section.SectionInformation.IsProtected)
		{
			section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
			section.SectionInformation.ForceSave = true;
			config.Save(ConfigurationSaveMode.Full);

			// Reset configuration object!
			ConfigurationManager.RefreshSection(sectionName);
		}                
	}
	catch (Exception ex)
	{
		// Do exception tracing here
		this.Stop();
	}
}