Object Reference error from IIS Componnet

Binumon George 161 Reputation points
2022-09-02T05:36:56.54+00:00

One of c# windows application i am checking IIS components like windows authentication, Forms authentication etc installed or not. To Avoid object Reference error, if not installed components i am using below code

RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(@"Software\Microsoft\InetStp\Components");

 isFormsAuthenticationInstalled(registryKey )  

 private bool isFormsAuthenticationInstalled(RegistryKey registryKey)  
    {  
        string sRegistryValue = registryKey.GetValue(@"FormsAuthentication-1")?.ToString()??"0";  
        if (sRegistryValue == "1")  
            return true;  
        else  
            return false;  
    }  

You can see i purposefully provided 'FormsAuthentication-1' To generate error in my local PC. but not getting Exception. But the same exe put in another system giving object reference error. Why?. New PC not installed IIS or visual studio

Internet Information Services
{count} votes