InPlaceHostingManager.AssertApplicationRequirements Method

Definition

Determines whether the ClickOnce application has the appropriate permissions and platform dependencies to run on the local computer.

Overloads

AssertApplicationRequirements()

Determines whether the ClickOnce application has the appropriate permissions and platform dependencies to run on the local computer.

AssertApplicationRequirements(Boolean)

Determines whether the ClickOnce application has the appropriate permissions and platform dependencies to run on the local computer.

AssertApplicationRequirements()

Determines whether the ClickOnce application has the appropriate permissions and platform dependencies to run on the local computer.

C#
public void AssertApplicationRequirements();

Exceptions

Raised if this method is called before the GetManifestAsync() method.

Examples

The following code example demonstrates the use of AssertApplicationRequirements, which it calls in the body of a successful GetManifestCompleted event handler.

C#
void iphm_GetManifestCompleted(object sender, GetManifestCompletedEventArgs e)
{
    // Check for an error.
    if (e.Error != null)
    {
        // Cancel download and install.
        MessageBox.Show("Could not download manifest. Error: " + e.Error.Message);
        return;
    }

    // bool isFullTrust = CheckForFullTrust(e.ApplicationManifest);

    // Verify this application can be installed.
    try
    {
        // the true parameter allows InPlaceHostingManager
        // to grant the permissions requested in the applicaiton manifest.
        iphm.AssertApplicationRequirements(true) ; 
    }
    catch (Exception ex)
    {
        MessageBox.Show("An error occurred while verifying the application. " +
            "Error: " + ex.Message);
        return;
    }

    // Use the information from GetManifestCompleted() to confirm 
    // that the user wants to proceed.
    string appInfo = "Application Name: " + e.ProductName;
    appInfo += "\nVersion: " + e.Version;
    appInfo += "\nSupport/Help Requests: " + (e.SupportUri != null ?
        e.SupportUri.ToString() : "N/A");
    appInfo += "\n\nConfirmed that this application can run with its requested permissions.";
    // if (isFullTrust)
    // appInfo += "\n\nThis application requires full trust in order to run.";
    appInfo += "\n\nProceed with installation?";

    DialogResult dr = MessageBox.Show(appInfo, "Confirm Application Install",
        MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
    if (dr != System.Windows.Forms.DialogResult.OK)
    {
        return;
    }

    // Download the deployment manifest. 
    iphm.DownloadProgressChanged += new EventHandler<DownloadProgressChangedEventArgs>(iphm_DownloadProgressChanged);
    iphm.DownloadApplicationCompleted += new EventHandler<DownloadApplicationCompletedEventArgs>(iphm_DownloadApplicationCompleted);

    try
    {
        // Usually this shouldn't throw an exception unless AssertApplicationRequirements() failed, 
        // or you did not call that method before calling this one.
        iphm.DownloadApplicationAsync();
    }
    catch (Exception downloadEx)
    {
        MessageBox.Show("Cannot initiate download of application. Error: " +
            downloadEx.Message);
        return;
    }
}

/*
private bool CheckForFullTrust(XmlReader appManifest)
{
    if (appManifest == null)
    {
        throw (new ArgumentNullException("appManifest cannot be null."));
    }

    XAttribute xaUnrestricted =
        XDocument.Load(appManifest)
            .Element("{urn:schemas-microsoft-com:asm.v1}assembly")
            .Element("{urn:schemas-microsoft-com:asm.v2}trustInfo")
            .Element("{urn:schemas-microsoft-com:asm.v2}security")
            .Element("{urn:schemas-microsoft-com:asm.v2}applicationRequestMinimum")
            .Element("{urn:schemas-microsoft-com:asm.v2}PermissionSet")
            .Attribute("Unrestricted"); // Attributes never have a namespace

    if (xaUnrestricted != null)
        if (xaUnrestricted.Value == "true")
            return true;

    return false;
}
*/

Remarks

You must call AssertApplicationRequirements after GetManifestAsync returns successfully. You must not call DownloadApplicationAsync unless you call AssertApplicationRequirements, and it returns without error.

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

AssertApplicationRequirements(Boolean)

Determines whether the ClickOnce application has the appropriate permissions and platform dependencies to run on the local computer.

C#
public void AssertApplicationRequirements(bool grantApplicationTrust);

Parameters

grantApplicationTrust
Boolean

If true, the application will attempt to elevate its permissions to the required level.

Remarks

If grantApplicationTrust is true, InPlaceHostingManager will grant the application elevated permissions if it requires them. This is only possible if InPlaceHostingManager is able to grant those permissions. For example, if a ClickOnce application is being installed as part of a larger package and the installer has been granted full trust, InPlaceHostingManager will be able to grant the ClickOnce application full trust. If grantApplicationTrust is false, the application will not be granted any permissions.

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1