本文整理汇总了C#中System.Security.Permissions.SecurityPermission.Demand方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityPermission.Demand方法的具体用法?C# SecurityPermission.Demand怎么用?C# SecurityPermission.Demand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Permissions.SecurityPermission
的用法示例。
在下文中一共展示了SecurityPermission.Demand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clerk
public Clerk(string compensator, string description, CompensatorOptions flags)
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
permission.Assert();
this.Init(compensator, description, flags);
}
示例2: Install
public override void Install(IDictionary stateSaver)
{
try
{
SecurityPermission permission =
new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
}
catch (SecurityException)
{
throw new InstallException(
"You have insufficient privileges to " +
"register a trust relationship. Start Excel " +
"and confirm the trust dialog to run the addin.");
}
Uri deploymentManifestLocation = null;
// NodeXLModification
//
// "deploymentManifestLocation" parameter name changed to
// "deploymentLocation" to make it consistent with
// ClickOnceInstaller.cs.
if (Uri.TryCreate(Context.Parameters["deploymentLocation"],
UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false)
{
throw new InstallException(
"The location of the deployment manifest is missing or invalid.");
}
AddInSecurityEntry entry = new AddInSecurityEntry(
deploymentManifestLocation, RSA_PublicKey);
UserInclusionList.Add(entry);
stateSaver.Add("entryKey", deploymentManifestLocation);
base.Install(stateSaver);
}
示例3: ClerkMonitor
public ClerkMonitor()
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
permission.Assert();
this._monitor = new CrmMonitor();
this._version = 0;
}
示例4: Assert
public void Assert()
{
// We must have the "Assertion" security flag for this to work.
SecurityPermission perm;
perm = new SecurityPermission(SecurityPermissionFlag.Assertion);
perm.Demand();
// Assert this permission.
Assert(2);
}
示例5: AnimateWindow
internal static void AnimateWindow(Control control, int time, AnimationFlags flags)
{
try
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
AnimateWindow(new HandleRef(control, control.Handle), time, flags);
}
catch (SecurityException) { }
}
示例6: AnimateWindow
internal static void AnimateWindow(Control control, int time, AnimationFlags flags)
{
Contract.Requires<ArgumentNullException>(control != null);
try
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
AnimateWindow(new HandleRef(control, control.Handle), time, flags);
}
catch (SecurityException) { }
}
示例7: DoWork
public void DoWork()
{
// Note that because DoDangerousThing is public, this
// security check does not resolve the violation.
// This only checks callers that go through DoWork().
SecurityPermission secPerm = new SecurityPermission(
SecurityPermissionFlag.ControlPolicy |
SecurityPermissionFlag.ControlEvidence
);
secPerm.Demand();
DoDangerousThing();
}
开发者ID:terryjintry,项目名称:OLSource1,代码行数:12,代码来源:ca2118--review-suppressunmanagedcodesecurityattribute-usage_3.cs
示例8: Serializer
/// <summary>
/// Static Constructor is used to set the CanBinarySerialize value only once for the given security policy
/// </summary>
static Serializer()
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
try
{
sp.Demand();
CanBinarySerialize = true;
}
catch(SecurityException)
{
CanBinarySerialize = false;
}
}
示例9: TRACKMOUSEEVENT
/// <summary>
/// Creates a new TRACKMOUSEEVENT struct with default settings
/// </summary>
public TRACKMOUSEEVENT()
{
// Marshal.SizeOf() uses SecurityAction.LinkDemand to prevent
// it from being called from untrusted code, so make sure we
// have permission to call it
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
this.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT));
this.dwFlags = 0;
this.hwndTrack = IntPtr.Zero;
this.dwHoverTime = 100;
}
示例10: RemoveEventHandler
public override void RemoveEventHandler(object target, Delegate handler) {
if (Marshal.IsComObject(target)) {
// retrieve sourceIid and dispid
Guid sourceIid;
int dispid;
GetDataForComInvocation(_innerEventInfo, out sourceIid, out dispid);
// now validate the caller can call into native and redirect to ComEventHelpers.Combine
SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
perm.Demand();
System.Runtime.InteropServices.ComEventsHelper.Remove(target, sourceIid, dispid, handler);
} else {
// we are dealing with a managed object - just add the delegate through relection
_innerEventInfo.RemoveEventHandler(target, handler);
}
}
示例11: Install
public override void Install(System.Collections.IDictionary stateSaver)
{
try
{
SecurityPermission permission =
new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
}
catch (SecurityException)
{
throw new InstallException(
"You have insufficient privileges to " +
"install the add-in into the ClickOnce cache. " +
"Please contact your system administrator.");
}
string deploymentLocation = Context.Parameters["deploymentLocation"];
if (String.IsNullOrEmpty(deploymentLocation))
{
throw new InstallException("Deployment location not configured. Setup unable to continue");
}
string arguments = String.Format(
"/S /I \"{0}\"", deploymentLocation);
int exitCode = ExecuteVSTOInstaller(arguments);
if (exitCode != 0)
{
string message = null;
switch (exitCode)
{
case -300:
message = String.Format(
"The Visual Studio Tools for Office solution was signed by an untrusted publisher and as such cannot be installed automatically. Please use your browser to navigate to {0} in order to install the solution manually. You will be prompted if the solution is trusted for execution.",
deploymentLocation);
break;
default:
message = String.Format(
"The installation of the ClickOnce solution failed with exit code {0}",
exitCode);
break;
}
throw new InstallException(message);
}
stateSaver.Add("deploymentLocation", deploymentLocation);
base.Install(stateSaver);
}
示例12: GetPermissions
private static void GetPermissions()
{
if (!m_Initialized)
{
//test RelectionPermission
CodeAccessPermission securityTest;
try
{
securityTest = new ReflectionPermission(PermissionState.Unrestricted);
securityTest.Demand();
m_ReflectionPermission = true;
}
catch
{
//code access security error
m_ReflectionPermission = false;
}
//test WebPermission
try
{
securityTest = new WebPermission(PermissionState.Unrestricted);
securityTest.Demand();
m_WebPermission = true;
}
catch
{
//code access security error
m_WebPermission = false;
}
//test WebHosting Permission (Full Trust)
try
{
securityTest = new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted);
securityTest.Demand();
m_AspNetHostingPermission = true;
}
catch
{
//code access security error
m_AspNetHostingPermission = false;
}
m_Initialized = true;
//Test for Unmanaged Code permission
try
{
securityTest = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
securityTest.Demand();
m_UnManagedCodePermission = true;
}
catch (Exception e)
{
m_UnManagedCodePermission = false;
}
}
}
示例13: SetCompressionProperties
/// <summary>
/// Sets the compression properties
/// </summary>
private void SetCompressionProperties()
{
switch (_archiveFormat)
{
case OutArchiveFormat.Tar:
break;
default:
ISetProperties setter = CompressionMode == CompressionMode.Create && _updateData.FileNamesToModify == null
? (ISetProperties)SevenZipLibraryManager.OutArchive(
_archiveFormat, this)
: (ISetProperties)SevenZipLibraryManager.InArchive(
Formats.InForOutFormats[_archiveFormat], this);
if (setter == null)
{
if (!ThrowException(null,
new CompressionFailedException(
"The specified archive format is unsupported.")))
{
return;
}
}
if (_volumeSize > 0 && ArchiveFormat != OutArchiveFormat.SevenZip)
{
throw new CompressionFailedException("Unfortunately, the creation of multivolume non-7Zip archives is not implemented. It will be one day, though.");
}
if (CustomParameters.ContainsKey("x") || CustomParameters.ContainsKey("m"))
{
if (
!ThrowException(null,
new CompressionFailedException(
"The specified compression parameters are invalid.")))
{
return;
}
}
var names = new List<IntPtr>(2 + CustomParameters.Count);
var values = new List<PropVariant>(2 + CustomParameters.Count);
#if !WINCE
var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
#endif
#region Initialize compression properties
if (_compressionMethod == CompressionMethod.Default)
{
names.Add(Marshal.StringToBSTR("x"));
values.Add(new PropVariant());
foreach (var pair in CustomParameters)
{
names.Add(Marshal.StringToBSTR(pair.Key));
var pv = new PropVariant();
if (pair.Key == "fb" || pair.Key == "pass" || pair.Key == "d")
{
pv.VarType = VarEnum.VT_UI4;
pv.UInt32Value = Convert.ToUInt32(pair.Value, CultureInfo.InvariantCulture);
}
else
{
pv.VarType = VarEnum.VT_BSTR;
pv.Value = Marshal.StringToBSTR(pair.Value);
}
values.Add(pv);
}
}
else
{
names.Add(Marshal.StringToBSTR("x"));
names.Add(_archiveFormat == OutArchiveFormat.Zip
? Marshal.StringToBSTR("m")
: Marshal.StringToBSTR("0"));
values.Add(new PropVariant());
var pv = new PropVariant
{
VarType = VarEnum.VT_BSTR,
Value = Marshal.StringToBSTR(Formats.MethodNames[_compressionMethod])
};
values.Add(pv);
foreach (var pair in CustomParameters)
{
names.Add(Marshal.StringToBSTR(pair.Key));
pv = new PropVariant();
if (pair.Key == "fb" || pair.Key == "pass" || pair.Key == "d")
{
pv.VarType = VarEnum.VT_UI4;
pv.UInt32Value = Convert.ToUInt32(pair.Value, CultureInfo.InvariantCulture);
}
else
{
pv.VarType = VarEnum.VT_BSTR;
pv.Value = Marshal.StringToBSTR(pair.Value);
}
values.Add(pv);
}
}
#endregion
//.........这里部分代码省略.........
示例14: SetSessionVariables
private void SetSessionVariables(HttpApplication application)
{
string queryStringAppPath = string.Empty;
string queryStringApplicationPhysicalPath = string.Empty;
string applicationPath = string.Empty;
string applicationPhysicalPath = string.Empty;
string setAppPath = string.Empty;
string setAppPhysPath = string.Empty;
try {
SecurityPermission permission = new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
} catch {
Exception permissionException = new Exception((string)HttpContext.GetGlobalResourceObject("GlobalResources", "FullTrustRequired"));
WebAdminPage.SetCurrentException(application.Context, permissionException);
application.Server.Transfer("~/error.aspx");
}
if (application.Context.Request != null) {
queryStringAppPath = (string) application.Context.Request.QueryString["applicationUrl"];
queryStringApplicationPhysicalPath = (string) application.Context.Request.QueryString["applicationPhysicalPath"];
}
if (application.Context.Session != null) {
if (application.Context.Session[APP_PATH] != null) {
applicationPath = (string)application.Context.Session[APP_PATH];
}
if (application.Context.Session[APP_PHYSICAL_PATH] != null) {
applicationPhysicalPath = (string)application.Context.Session[APP_PHYSICAL_PATH];
}
}
if ((String.IsNullOrEmpty(queryStringAppPath) && applicationPath == null) ||
(String.IsNullOrEmpty(queryStringApplicationPhysicalPath) && applicationPhysicalPath == null) ) {
application.Server.Transfer("~/home0.aspx", false);
return;
}
if (!String.IsNullOrEmpty(queryStringAppPath)) {
setAppPath = queryStringAppPath;
} else if (!String.IsNullOrEmpty(applicationPath)) {
setAppPath = applicationPath;
}
if (!String.IsNullOrEmpty(queryStringApplicationPhysicalPath)) {
setAppPhysPath = queryStringApplicationPhysicalPath;
} else if (!String.IsNullOrEmpty(applicationPhysicalPath)) {
setAppPhysPath = applicationPhysicalPath;
}
if (application.Context.Session != null) {
application.Context.Session[APP_PATH] = setAppPath;
application.Context.Session[APP_PHYSICAL_PATH] = setAppPhysPath;
application.Context.Session[REMOTING_MANAGER] = new WebAdminRemotingManager(setAppPath, setAppPhysPath, application.Context.Session);
}
}
示例15: DataAccessObject
internal DataAccessObject()
{
SecurityPermission perm = new SecurityPermission(PermissionState.Unrestricted);
perm.Demand();
}