代码访问流程.docx

上传人:b****2 文档编号:25888575 上传时间:2023-06-16 格式:DOCX 页数:19 大小:26.25KB
下载 相关 举报
代码访问流程.docx_第1页
第1页 / 共19页
代码访问流程.docx_第2页
第2页 / 共19页
代码访问流程.docx_第3页
第3页 / 共19页
代码访问流程.docx_第4页
第4页 / 共19页
代码访问流程.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

代码访问流程.docx

《代码访问流程.docx》由会员分享,可在线阅读,更多相关《代码访问流程.docx(19页珍藏版)》请在冰豆网上搜索。

代码访问流程.docx

代码访问流程

要在您的ASP.NET应用程序中使用代码访问安全性:

∙Step1.第1步。

Identifythepermissionsyourapplicationneeds.确定您的应用程序需要的权限。

∙Step2.第2步。

Chooseanappropriatetrustlevel.选择适当的信任级别。

∙Step3.第3步。

ConfigureyourASP.NETapplication.配置您的ASP.NET应用程序。

∙Step4.第4步。

Optionallycreateacustomtrustlevel.也可以创建一个自定义的信任级别。

Step1.第1步。

IdentifythePermissionsYourApplicationNeeds您的应用需求确定权限

Identifytheprecisesetofcodeaccesssecuritypermissionsthatyourapplicationrequires.确定精确的代码访问安全权限设置,您的应用需要。

YoucandothisbymanuallyreviewingyourcodeorbyusingthePermissionsCalculatortool(Permcalc.exe).您可以通过手动检查你的代码,或使用权限计算器工具(Permcalc.exe)。

ManuallyReviewingCodetoIdentityPermissionRequirements手动审查代码标识权限要求

Tomanuallyidentifypermissionrequirements,youneedtoanalyzeyourcodeanddeterminethetypesofresourcesitaccesses,thekindofresourceaccessitrequires(suchasread/write),andtheprivilegedoperationsitperforms.要手动确定的权限要求,你需要分析代码并确定资源访问,资源访问的要求(如读/写),它执行特权操作的类型。

Themaindifficultywithtryingtomanuallyidentifypermissionrequirementsoccursifyourcodecallsotherassemblies,suchasthird-partyassembliesorsystemassemblies.如果您的代码调用其他组件,如第三方组件或系统组件,试图手动识别权限要求的主要困难。

Identifyingtheirpermissionrequirementscanbeverydifficult.确定其权限要求是非常困难的。

ThisiswherethePermCalctoolcanhelp.这是PermCalc工具可以帮助。

Formoreinformationaboutthepermissionsyouneedtobeabletoaccessspecificresourcestypes,seethe"ResourceAccessPermissionsSummary"sectionlaterinthisdocument.的权限,你需要能够访问特定的资源类型的更多信息,请参阅本文档后面的“资源访问权限概要”一节。

Formoreinformationaboutprivilegedoperationsandthepermissionsyouneedtobeabletoperformthem,seethe"PrivilegedOperationPermissionsSummary"sectionlaterinthisdocument.有关特权操作的权限,你需要能够执行他们的详细信息,请参阅本文档后面的“特权操作权限概要”一节。

UsingthePermissionsCalculatorTool使用权限计算器工具

Ifyouuseseparateassembliesforyourapplication'sbusinessanddataaccesslogicandplacethemeitherinyourapplication's\bindirectoryortheglobalassemblycache,youcanrunPermCalconthoseassemblies.如果使用单独的应用程序的业务和数据访问逻辑组件和它们放置在您的应用程序的\bin目录或全局程序集缓存,你可以运行这些程序集PermCalc。

YoucannotrunPermCalcdirectlyon.aspxWebpages.您不能直接运行PermCalc的。

ASPXWeb页。

Toseethepermissionrequirementsofanassembly要查看程序集的权限要求

1.RunthefollowingcommandfromaMicrosoftVisualStudio.NET2005commandwindow.NET2005命令窗口运行以下命令从一个MicrosoftVisualStudio。

permcalc-Showpermcalc展<的AssemblyName>

Thefollowingissampleoutputfromthiscommand.以下是这个命令的输出范例。

xmlversion="1.0"?

><?

XML版本=“1.0”?

>

class="System.Security.PermissionSet">类=“System.Security.PermissionSet”>

class="System.Security.Permissions.RegistryPermission,mscorlib,类=“System.Security.Permissions.RegistryPermission,MSCORLIB

Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"版本=2.0.0.0,文化=中性公钥=b77a5c561934e089“

Read="true"/>阅读“真实”/>

Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"版本=2.0.0.0,文化=中性公钥=b77a5c561934e089“

Unrestricted="true"/>无限制=“TRUE”/>

Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"版本=2.0.0.0,文化=中性公钥=b77a5c561934e089“

Read="true"/>阅读“真实”/>

Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"版本=2.0.0.0,文化=中性公钥=b77a5c561934e089“

Unrestricted="true"/>无限制=“TRUE”/>

2.Examinethepermissionslistedintheelement.检查<需求>元素中列​​出的权限。

Theserepresentthepermissionsthattheassemblyneeds.这些代表大会所需要的权限。

Inthiscase,theassemblyneedsRegistryPermissionandFileIOPermission.在这种情况下,大会需要RegistryPermission的和FileIOPermission的。

3.

4.

5.class="System.Security.Permissions.FileIOPermission,mscorlib,类=“System.Security.Permissions.FileIOPermission,MSCORLIB

6.Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"版本=2.0.0.0,文化=中性公钥=b77a5c561934e089“

7.Unrestricted="true"/>无限制=“TRUE”/>

YoucanpassanumberofassembliestothePermCalctoolatthesametime,asshowninthefollowingcommandexample.您可以通过一些程序集PermCalc工具在同一时间,在下面的命令示例所示。

permcalc-Showpermcalc显示

NoteIfanyresourceisaccesseddirectlyfroman.aspxpage,youwillneedtomanuallycalculatethepermissionrequirementsforthatresource.注意:

如果任何资源。

aspx页面直接访问,您将需要手动计算该资源的权限要求。

PermCalcworksonlywithassemblies.PermCalc工程与集会。

Step2.第2步。

ChooseanAppropriateTrustLevel选择适当的信任级别

Trytoevaluatewhetherthepermissionsrequiredforyourapplicationmatchthoseprovidedbyanyofthestandardtrustlevels.尝试评估为您的应用程序所需的权限是否匹配任何标准的信任级别提供的。

TrustLevelsSummary信托级别摘要

ThecapabilitiesavailabletoapplicationsrunningatthevarioustrustlevelsaresummarizedinTable1.表1总结了在不同的信任级别运行的应用程序的能力。

Table1.表1。

TrustLevelsandTheirKeyCapabilitiesandRestrictions信托水平和他们的关键功能和限制

TrustLevel信任级别

KeyCapabilitiesandRestrictions关键功能和限制

Full全

Norestrictionsimposedbycodeaccesssecurity.没有限制代码访问安全性。

High高

Nounmanagedcode.没有非托管代码。

Noenterpriseservices.没有企业的服务。

CanaccessMicrosoftSQLServerandotherOLEDBdatasources.可以访问MicrosoftSQLServer和其他OLEDB数据源。

Cansende-mailbyusingSMTPservers.可以使用SMTP服务器发送电子邮件。

Verylimitedreflectionpermissions.非常有限的反射权限。

Noabilitytoinvokecodebyusingreflection.没有能力通过使用反射调用代码。

Abroadsetofotherframeworkfeaturesareavailable.提供一套广泛的框架功能。

Applicationshavefullaccesstothefilesystemandtosockets.应用有充分的访问文件系统和插座。

Medium中等

Permissionsarelimitedtowhattheapplicationcanaccesswithinthedirectorystructureoftheapplication.权限是有限的应用程序可以访问的应用程序目录结构内。

Nofileaccessispermittedoutsideoftheapplication'svirtualdirectoryhierarchy.没有文件允许访问应用程序的虚拟目录层次结构之外。

CanaccessSQLServer.可以访问SQLServer。

Cansende-mailbyusingSMTPservers.可以使用SMTP服务器发送电子邮件。

Limitedrightstocertaincommonenvironmentvariables.某些共同的环境变量的有限权利。

Noreflectionpermissionswhatsoever.没有反射任何权限。

Nosocketspermission.没有插座的权限。

ToaccessWebresources,youmustexplicitlyaddendpointURLs—eitherintheoriginUrlattributeoftheelementorinsidethepolicyfile.访问Web资源,你必须明确地加入端点URLoriginUrl属性<信任>元素或内部的政策文件。

Low低

Intendedtomodeltheconceptofaread-onlyapplicationwithnonetworkconnectivity.模型与没有网络连接的只读应用程序的概念。

ReadonlyaccessforfileI/Owithintheapplication'svirtualdirectorystructure.只读文件访问的I/O在应用程序的虚拟目录结构。

Minimal最小

Executeonly.只执行。

NoabilitytochangetheIPrincipalonathreadorontheHttpContext.没有能力改变一个线程的HttpContext的IPrincipal。

Ifyourapplicationcallsunmanagedcode,itmustrunwithFulltrust.如果您的应用程序调用非托管代码,它必须运行的完全信任。

Eventheleastrestrictivepartialtrustlevel,High,doesnotpermitcallstounmanagedcode.即使是限制最少的部分信任的水平,高,不允许调用非托管代码。

Tochooseanappropriatetrustlevel要选择一个合适的的信任级别

1.Examineeachtrustlevel,beginningwithHightrust.检查每个信任级别,高信任的开始。

2.LookinsidetheHightrustpolicyfile,web_HighTrust.config.往里高信任的政策文件,web_HighTrust.config。

3.IfyourapplicationrequiresfewercodeaccesssecuritypermissionsthanthoseprovidedbytheHightrustlevel,moveontoconsiderMediumtrust.如果应用程序需要比高信任级别提供的代码访问安全权限少,考虑中等信任。

4.Repeattheprocess,movingfromMediumtoLowtoMinimal,andkeepevaluatingthepartialtrustlevelsuntilyoureachanexactmatchtoyourapplication'srequirementsoruntilyourapplication'srequiredpermissionsslightlyexceedapartialtrustlevel.重复这个过程中,由中等至低到最小,并保持评估的部分信任的水平,直到到达一个完全匹配您的应用程序的要求,或您的应用程序所需的权限,直到略超过部分信任水平。

Thisprocesswillhelpyoutoidentifyatrustlevelthatmatchesyourapplication'scodeaccesssecuritypermissionrequirementsascloselyaspossiblebutdoesnotgrantpermissionsthatyourapplicationdoesnotneed.这一过程将帮助您识别匹配您的应用程序的代码访问安全权限要求尽可能接近但不授予权限,您的应用程序并不需要的信任级别。

Step3.第3步。

ConfigureYourASP.NETApplication配置您的ASP.NET应用程序

YoucanconfigureyourASP.NETapplicationtouseastandardtrustleveleitherinyourapplication'sWeb.configfileorinthemachine-levelWeb.configfile.你可以配置你的ASP.NET应用程序在您的应用程序的Web.config文件中或在计算机级别的Web.config文件中使用标准的信任级别。

Machine-levelconfigurationaffectsalltheASP.NETWebapplicationsandWebserviceshostedonthatserver.机级别的配置影响到所有的ASP.NETWeb应用程序和Web服务的服务器上宿主。

Application-levelconfigurationaffectsonlyaspecifica

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1