views:

210

answers:

1

I have an Xbap application that is part of an intranet application that needs file system access.

Ive made the app full trust, signed it with a valid certificate and imported the cert into ie and the xbap works perfectly.

My issue is that I want to gracefully handle a Permission Denied exception if the user doen't have the certificate installed, ie does not have File system IO access

I thought I could achieve this by running the xbap in partial trust mode and using something like the following to test for permissions

CodeAccessPermission p = new FileIOPermission(FileIOPermissionAccess.Write, @"c:\newfile.txt");

try
{
    p.Demand();
    // Has access
}
catch (Exception ex)
{
    // Does not have access
}

The issue is however that the above code will always fail if you have not added the FileIOPermissions permission to the "Permissions required by the application" list in the security tab of your project's properties window... even if run from your local file system instead of through a web server.

BUT

If i do add the FileIOPermissions permission, and the user does not have the certificate installed, none of my code is ever hit and the xbap throws a generic "Trust Not Granted" error screen... which i dont want, i want to show my users a proper error screen that explains what they can do to fix this error

any ideas?

A: 

You can manually edit the app.manifest file to request lower minimum permissions for your application, and then (in theory) you testing code will not always fail when you ask for the file permission, but as intended will fail only when user has not granted your code the required permissions.

Alex Shnayder