国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Writing Secure Code In CSharp

2024-07-21 02:20:19
字體:
來源:轉載
供稿:網友
writing secure code using csharpsubmitted byuser leveldate of submissionc.vinodh kumarintermediate04/06/2001
mobile code, which come from various sources like e-mail, documents and downloaded code over the internet are the main cause for the damage, destroy or copy private data. so to help protect computer systems from malicious mobile code and to provide a way to allow mobile code to run safely, the .net framework provides a security mechanism called code access security .
code access security is a mechanism that controls the access code has to protected resources and operations. net framework, code access security performs functions like defining permission, enables administrators to configure security policy, allows code to request the permissions it requires in order to run, grants permissions to each assembly that is loaded, based on the permissions requested by the code and enables code to demand that its callers have specific permissions.
code access security is a mechanism that grants/denies access to resources within a method call. for example, code written by a person may be allowed to write to the disk while code from another one may be forbidden from accessing the disk. this control can be enforced even if the code written by both of them is used within a single application.
system.security namespace provides the underlying structure of the .net framework security system, including interfaces, attributes, exceptions, and base classes for permissions and codeaccesspermission class defines the underlying structure of all code access permissions.
let see a sample application, which attempts to access a disk file and an environment variable .
code shown below will create permission to set read access to temp environment and full access to some files. before changing every file will be have a default permission set.
  
         // create a permission set that allows read access to the temp
         // environment variable and read, write, and append access to somefile from
        //default permission
        permissionset ps = new permissionset(permissionstate.none);
         ps.addpermission(
            new environmentpermission(environmentpermissionaccess.read, "temp"));
       //adding various type of file level permission
         ps.addpermission(
            new fileiopermission(fileiopermissionaccess.read |
                fileiopermissionaccess.write | fileiopermissionaccess.append,
                "somefile"));
         // make the permissions indicate all that we're allowed to do.
        ps.assert();

permissionset class (in system.security) represents a collection and it contains many different kinds of permissions, and supports the methods that use and modify those permissions. we can add, remove, assert, deny and copy permission.
        // deny access to the resources we specify
        ps.deny();      
  // make the permissions indicate the only things that we're allowed to do.
        ps.permitonly();
        // remove the fileiopermissions from the permission set
        ps.removepermission(typeof(fileiopermission))
// remove the environmentpermission from the permission set
        ps.removepermission(typeof(environmentpermission));
deny method prevents callers from accessing the protected resource even if they have been granted permission to access it. pemitonly ensures that only the resources specified by this permission object can be accessed, even if the code has been granted permission to access other resources. fileiopermissionaccess specifies the actions that can be performed on the file or folder. environmentpermission class as the ability to query and modify system and user environment variables.
conclusion:we have seen how to write a secure code using the publicly available .net sdk. although what i have shown you is simple in functionality you can even create your own code access permission and much more advance security futures in you code.

source code:  codesecureusingcsharp1.zip 2k
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 伊春市| 铜陵市| 嘉荫县| 集贤县| 张家界市| 嘉黎县| 扎囊县| 洛阳市| 台安县| 赣榆县| 乌审旗| 连州市| 崇信县| 清河县| 慈溪市| 肇庆市| 息烽县| 呼图壁县| 双辽市| 呼玛县| 富裕县| 阿拉善右旗| 伊金霍洛旗| 修水县| 嘉祥县| 阿坝| 江油市| 渑池县| 枣强县| 壤塘县| 临沂市| 江山市| 莲花县| 剑河县| 苍梧县| 宜都市| 汉川市| 永济市| 达日县| 吴川市| 阿拉善右旗|