• 构建安全高效的Microsoft ASP.NET 应用的最佳实践和技术


    一、性能与缓存
    *ASP.NET的性能状况 ASP.NET的引擎从原理上保证高性能 一次编译 Internet Explorer-->Parser-->Compiler-->Assembly Cashe-->Memory-->OutputCache-->回来 第二次运行 Internet Explorer-->-->Assembly Cashe-->Memory-->OutputCache-->回来

    *ASP.NET的引擎从原理上保证高性能
    CLR Just-in-time Compiler
    对多CPU有很好的支持
    运行时优化编译
    *引擎的优化不能彻底解决性能问题
    代码逻辑不优化
    引擎无法控制的,潜在的性能优化点


    *性能问题与优化原则
    性能参数
    吞吐量
    响应时间
    执行时间
    可伸缩性

    基本优化原则
    减少不必要的资源消耗
    CPU,内存

    *性能提高的技巧
    避免不必要的执行操作
    Page_Load和IsPostBack
    void Page_Load(Object sender,EventArgs e)
    {
     if(!Page.IsPostBack){......}
    }

    *页面执行顺序
    Page_Load-->Properties Change-->Action

    *性能提高的技巧
    关闭不必要的Session状态
    <%@ Page EnableSessionState="false" %>
    注意使用Server Control
    不必要时可以不使用Server Control
    不必要时可以关闭ViewState
    <asp:datagrid EnableViewState="false" runat="server" />
    <%@ Page EnableViewState="false" %>

    *不要用Exception控制程序流程
    try
    {
     result=100/num;
    }
    catch(Exception e)
    {
     result=0;
    }
    //--------------------------
    if(num!=0)
     result=100/num;
    else
     result=0;

    *禁用VB和JScript动态数据类型
    <%@ Page Language="VB" Strict="true" %>
    使用存储过程数据访问
    只读数据访问不要使用DataSet
    使用SqlDataReader代替DataSet
    SqlDataReader是read-only,forward-only
    关闭ASP.NET的Debug模式
    使用ASP.NET Output Cache缓冲数据

    *ASP.NET输出缓冲
    页面缓冲
    <%@OutputCache %>
    Duration
    VaryByParam
    片断缓冲
    VarByControl
    (用户空件)

    *数据缓冲
    过期依赖条件
    Cache.Insert("MyData",Source,newCacheDependency(Server.MapPath("authors.xml")));
    Cache.Insert("MyData",Source,null,DateTime.Now.AddHours(1),TimeSpan.Zero);
    Cache.Insert("MyData",Source,null,DateTime.MaxValue,TimeSpan.FromMinutes(20));


    二、ASP.NET应用安全事项

    1、输入验证[前端验证/后台验证]

    2、参数化查询

    3、存储过程

    4、html编码(防止javascript脚本执行) String.Format("Invalid Logon for {0},please try again!",Server.HtmlEncode(UserName));


    认证与授权
    配置管理
    Review production configuration:
    <customErrors> RemoteOnly or On
    <compilation> disable debugging
    Shared servers
    Use configuration lockdown
    <location allowOverride=“false”/>
    Isolate by process (IIS 6) and/or with <trust> level
    敏感数据
    会话管理
    使用加密
    1、加密类CryPtography
    2、随机类RNGCryptoServiceProvider
    异常管理
    最小权限

  • 相关阅读:
    使用Xshell为xftp开ssh通道代理
    linux下查找svn的相关目录的命令
    linux服务器A远程连接服务器B的mysql及1045错误
    怎样下载带权限认证的文件?
    Vue项目打包部署总结
    Vue项目打包压缩:让页面更快响应
    axios请求失败自动重发
    可用的后台管理系统
    vue组件间方式总结
    非脚手架创建vue项目,并使用webpack打包
  • 原文地址:https://www.cnblogs.com/bicabo/p/1646752.html
Copyright © 2020-2023  润新知