win2003/vs2005에서 테스트.
특정 URL에서 실행되는 스마트 클라이언트에 FullTrust 권한을 주는 코드.
.NET 관리 도구에서 설정을 확인할 수 있다.
using System;출처 ; http://msdn2.microsoft.com/ko-kr/library/system.security.policy.codeconnectaccess(VS.80).aspx 의 코드를 일부 수정.
using System.Security;
using System.Security.Policy;
using System.Windows.Forms;namespace DecisionCheck
{
class Program
{
Boolean returnBool()
{
return true;
}static void Main(string[] args)
{
const string userPolicyLevel = "Machine";
PolicyLevel level = null;
System.Collections.IEnumerator ph = SecurityManager.PolicyHierarchy();while (ph.MoveNext())
{
level = (PolicyLevel)ph.Current;
if (level.Label == userPolicyLevel)
break;}
// exist?
foreach (CodeGroup group in level.RootCodeGroup.Children)
{
// if (group.Name == "Decision")
// return;
}// Create Permission
NamedPermissionSet permissionSet = new NamedPermissionSet("FullTrust");
PolicyStatement policyStatement = new PolicyStatement(permissionSet);// URL Membership
IMembershipCondition membership = new UrlMembershipCondition(@"http://localhost/*");// codegroup to add
UnionCodeGroup ucg = new UnionCodeGroup(membership, policyStatement);// naming
ucg.Name = "Decision";
ucg.Description = "Security setting for DecisionWeb";// add to codegroup
level.RootCodeGroup.AddChild(ucg);
DialogResult result = MessageBox.Show("Continue to add security setting?", "Secutiry setup", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
SecurityManager.SavePolicy();
// navigate new url
System.Diagnostics.Process.Start(@"http://localhost/test.aspx");
}
}
}
}