本文整理汇总了C#中System.Security.PermissionSet.Assert方法的典型用法代码示例。如果您正苦于以下问题:C# System.Security.PermissionSet.Assert方法的具体用法?C# System.Security.PermissionSet.Assert怎么用?C# System.Security.PermissionSet.Assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.PermissionSet
的用法示例。
在下文中一共展示了System.Security.PermissionSet.Assert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayProfile
private void DisplayProfile()
{
try
{
System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
ps.Assert();
Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current;
UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);
ProfileSubtypePropertyManager pspm = upm.DefaultProfileSubtypeProperties;
UserProfile profile = upm.GetUserProfile(true); //_accountName);
this.Controls.Add(new Literal() { Text = "<table border='0' > <tr><td>Displayname</td><td>Value</td></tr>" });
string[] props = { "UserName", "FirstName", "LastName", "WorkEmail", "Department" };
foreach (string prop in props)
{
string text = string.Format("<tr><td>{0}</td><td>{1}</td></tr>",
profile[prop].ProfileSubtypeProperty.DisplayName,
profile[prop].Value);
this.Controls.Add(new Literal() { Text = text });
}
string txtEdit = "<tr><td colspan='2'>";
btnEdit = new Button() { Text = "Edit" };
this.Controls.Add(new Literal() { Text = txtEdit });
this.Controls.Add(btnEdit);
this.Controls.Add(new Literal() { Text = "</td></tr>" });
btnEdit.Click += new EventHandler(btnEdit_Click);
/*
foreach (ProfileSubtypeProperty prop in pspm.PropertiesWithSection)
{
if (prop.IsSection)
this.Controls.Add(new Literal() { Text = string.Format("<tr><td colspan='3'><b>Section: {0}</b></td></tr>", prop.DisplayName) });
else
{
string text = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>",
prop.DisplayName,
prop.Name,
profile[prop.Name].Value);
this.Controls.Add(new Literal() { Text = text });
}
}*/
this.Controls.Add(new Literal() { Text = "</table>" });
}
catch (Exception ex)
{
this.Controls.Add(new Literal() { Text = ex.ToString() });
}
finally
{
System.Security.CodeAccessPermission.RevertAssert();
}
}
示例2: GetErasFromRegistry
[System.Security.SecuritySafeCritical] // auto-generated
private static EraInfo[] GetErasFromRegistry()
{
// Look in the registry key and see if we can find any ranges
int iFoundEras = 0;
EraInfo[] registryEraRanges = null;
#if !MONO
try
{
// Need to access registry
PermissionSet permSet = new PermissionSet(PermissionState.None);
permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
permSet.Assert();
RegistryKey key = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(c_japaneseErasHive, false);
// Abort if we didn't find anything
if (key == null) return null;
// Look up the values in our reg key
String[] valueNames = key.GetValueNames();
if (valueNames != null && valueNames.Length > 0)
{
registryEraRanges = new EraInfo[valueNames.Length];
// Loop through the registry and read in all the values
for (int i = 0; i < valueNames.Length; i++)
{
// See if the era is a valid date
EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());
// continue if not valid
if (era == null) continue;
// Remember we found one.
registryEraRanges[iFoundEras] = era;
iFoundEras++;
}
}
}
catch (System.Security.SecurityException)
{
// If we weren't allowed to read, then just ignore the error
return null;
}
catch (System.IO.IOException)
{
// If key is being deleted just ignore the error
return null;
}
catch (System.UnauthorizedAccessException)
{
// Registry access rights permissions, just ignore the error
return null;
}
//
// If we didn't have valid eras, then fail
// should have at least 4 eras
//
if (iFoundEras < 4) return null;
//
// Now we have eras, clean them up.
//
// Clean up array length
Array.Resize(ref registryEraRanges, iFoundEras);
// Sort them
Array.Sort(registryEraRanges, CompareEraRanges);
// Clean up era information
for (int i = 0; i < registryEraRanges.Length; i++)
{
// eras count backwards from length to 1 (and are 1 based indexes into string arrays)
registryEraRanges[i].era = registryEraRanges.Length - i;
// update max era year
if (i == 0)
{
// First range is 'til the end of the calendar
registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
}
else
{
// Rest are until the next era (remember most recent era is first in array)
registryEraRanges[i].maxEraYear = registryEraRanges[i-1].yearOffset + 1 - registryEraRanges[i].yearOffset;
}
}
#endif
// Return our ranges
return registryEraRanges;
}
示例3: GetFullNameFromProfile
string GetFullNameFromProfile()
{
string FullName = string.Empty;
try
{
System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
ps.Assert();
Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current;
UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);
ProfileSubtypePropertyManager pspm = upm.DefaultProfileSubtypeProperties;
UserProfile profile = upm.GetUserProfile(true);
FullName = profile["FirstName"].Value + " " + profile["LastName"].Value;
}
catch (Exception) { }
return FullName;
}