Best way to determine if a WIF runtime is installed

Several pages of my ASP.Net application connect directly to another service using WIF. WIF just attacks here, and while it is installed on the testing and production servers, every time a new programmer or tester becomes the last and happens to get to these pages without installing the WIF installed on their machine, it gets YSOD and the error is that you didn’t find Microsoft.IdentityModel ... which they never read and instead turned off IM, informing me that my application is broken.

I would like to determine if the WIF runtime is installed and show every useful error message and a link to the download page if not. I do not want to check the specific .dll path, as this may change ... and there are already different paths for 3.5 and 4.0.

Is there a better way to determine if a WIF runtime is set?

(obviously on a page that no longer links to it ... which will not display correctly if it is not installed)

Edit

It looks like WIF is included with 4.5 , so a special 3.5 / 4.0 approach will be fine. No need to be in the future.

+5
source share
4 answers

Microsoft.IdentityModel.dll GAC try/catch -block , WIF, , / .

- , WIF: ( , ), , Windows Identity , Foundation, SOFTWARE\Microsoft\Windows Identity Foundation ( Wow6432Node 64- ).

+2

Microsoft:

Q: Under what registry key is WIF installed?
A: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsIdentityFoundation\setup\v3.5\.

+3
  • WIF .
  • WebPI WIF SDK.
  • , GAC, .
+1

Microsoft, , WIF, , .

:

/// <summary>
/// Determines if WIF is installed on the machine.
/// </summary>
public static class WifDetector
{
    /// <summary>
    /// Gets a value indicating that WIF appears to be installed.
    /// </summary>
    public static bool WifInstalled { get; private set; }

    static WifDetector()
    {
        WifInstalled = IsWifInstalled();
    }

    private static bool IsWifInstalled()
    {
        try
        {
            //return File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
            //                                "Reference Assemblies\\Microsoft\\Windows Identity Foundation\\v3.5\\Microsoft.IdentityModel.dll"));
            //The registry approach seems simpler.
            using( var registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows Identity Foundation") ?? 
                                     Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows Identity Foundation") )
            {
                return registryKey != null;
            }
        }
        catch
        {
            //if we don't have permissions or something, this probably isn't a developer machine, hopefully the server admins will figure out the pre-reqs.
            return true;
        }
    }
}

. , .

    private void CheckWifInstallation()
    {
        if (!WifDetector.WifInstalled)
        {
            var alert = new ClientSideAlert(
                    "This application requires the Windows Identity Foundation runtime to be installed on the webserver:\n");
            alert.AddMessageLine("Please install the appropriate WIF runtime for this operating system by visiting:\n");
            alert.AddMessageLine("http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=17331 \n");
            alert.AddMessageLine("or simply search for 'WIF runtime install'\n");
            alert.AddMessageLine("Thanks, and have a nice day!'");
            alert.Display(Page);
        }
    }

We don't have fancy Internet deployment packages for developer machines, they just come from the source and go. This will allow developers without this library not to lose time when they encounter an error loading YSOD and an incomprehensible assembly.

Thanks for the suggestions.

+1
source

All Articles