zoukankan      html  css  js  c++  java
  • crm具体问题具体实现

    • 国际化的实现
      1.创建项目ResourceLanguage
      2.添加资源文件ResourceLanguage.resx,添加数据(添加数据是最好不要使用html标记,这样会造成编译错误),编译
      这时资源文件的路径应该是resourceLanguage.ResourceLanguage.resource,为了调用方便,一般可以设置项目的名字空间为空,这样我们调用时,只用通过ResourceLanguage.resource访问就可以了
      3.下面是装载资源文件:
      const string baseResourceFile = "ResourceLanguage";
                      Assembly primaryResource 
      = Assembly.Load(baseResourceFile);
                      Application[
      "RM"= new ResourceManager(baseResourceFile, primaryResource);
      4.添加属性,用于获取资源包
          public class Root
          
      {
              
      public Root()
              
      {
              }


              
      private static ResourceManager _rm;
              
      public static ResourceManager rm
              
      {
                  
      get
                  
      {
                      
      if(_rm==null)
                          _rm 
      = (ResourceManager) HttpContext.Current.Application["RM"];
                      
      return _rm;
                  }

              }

          }
      5.调用
      Root.rm.GetString("Lgntxt4");

      (注意:国际化文档时,value值如果用到了HTML标记,请注意标记一定要规范,部分标记无法使用,不然会报告错误,如使用 标记,会报告xmlvalidatingreader 并相应地设置 entityheadling 属性的错误)
    • 身份验证票,验证用户权限以控制是否有权访问某页面(待续)
      1.web.config设置,采用Forms身份验证方式:
      <authentication mode="Forms">
                  
      <forms name=".CRM" protection="All" timeout="60" loginUrl="login.aspx" slidingExpiration="true" />
              
      </authentication>
      2.项目下各级目录下页面文件访问授权的设置:
      <configuration>
          
      <system.web>
          
      <authorization>
              
      <allow roles="SystemAdministrator,MembershipAdministrator" />
              
      <deny users="*" />
          
      </authorization>
          
      </system.web>

          
      <location path="ShowAllUsers.aspx">
            
      <system.web>
              
      <authorization>
                
      <allow roles="SystemAdministrator,MembershipAdministrator" users="?" />
              
      </authorization>
            
      </system.web>
          
      </location>
      </configuration>
      3.验证票的建立
      public FormsAuthenticationTicket(
      int version, //设为1
      string name, //用户标示
      DateTime issueDate, //Cookie 的发出时间, 设置为 DateTime.Now 
      DateTime expiration, //过期时间
      bool isPersistent, //是否持久性(根据需要设置,若是设置为持久性,在发出
      cookie时,cookie的Expires设置一定要设置)
      string userData, //这里用上面准备好的用逗号分割的role字符串
      string cookiePath // 设为"/",这要同发出cookie的路径一致,因为刷新cookie
      要用这个路径
      );

      FormsAuthenticationTicket Ticket 
      = new FormsAuthenticationTicket (1,"kent",DateTime.Now, DateTime.Now.AddMinutes(30), false,UserRoles,"/") ;

      4.生成验证票
      //将身份验证票加密序列化成一个字符串
      string HashTicket = FormsAuthentication.Encrypt (Ticket) ;
      //生成cookie
      HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) ;
      5.将身份验证票Cookie输出到客户端
      通过Response.Cookies.Add(UserCookie) 将身份验证票Cookie附加到输出的cookie集合中,发送到客户端.
      6.重定向到用户申请的初试页面.
      Context.Response.Redirect (Context.Request["ReturnUrl"]) ;
      7.基于角色访问授权
      protected void Application_AuthorizeRequest(object sender, System.EventArgs e)
      {
          HttpApplication App 
      = (HttpApplication) sender;
           HttpContext Ctx 
      = App.Context ; //获取本次Http请求相关的HttpContext对象
          if (Ctx.Request.IsAuthenticated == true//验证过的用户才进行role的处理
          {
              FormsIdentity Id 
      = (FormsIdentity)Ctx.User.Identity ;
              FormsAuthenticationTicket Ticket 
      = Id.Ticket ; //取得身份验证票
              string[] Roles = Ticket.UserData.Split (',') ; //将身份验证票中的role数据转成字符串数组
              Ctx.User = new GenericPrincipal (Id, Roles) ; //将原有的Identity加上角色信息新建一个GenericPrincipal表示当前用户,这样当前用户就拥有了role信息
          }

      }
    • 地址重载(待续)

    • 页面存储机制(viewstate)(待续)
      1.重载LoadPageStateToPersistenceMedium方法
      protected override object LoadPageStateFromPersistenceMedium()
              
      {
                  
      if (_formatter == null)
                  
      {
                      _formatter 
      = new LosFormatter();
                  }


                  
      string str = Request.Form["__VIEWSTATE_KEY"];
                  
      if (!str.StartsWith("VIEWSTATE#"))
                  
      {
                      
      throw new Exception("Invalid viewstate key:" + str);
                  }

      #if VIEWSTATETOSQLSERVER

                  
      //从数据库中获取ViewState,参数为SessionID
                  db.GetViewState(a);
                  
      //操作失败则跳转到上一页面    
                  
                  
      //返回序列化后的viewstate
                  return _formatter.Deserialize(viewState);
      #else
                  
      if (!str.StartsWith("VIEWSTATE#"))
                  
      {
                      
      throw new Exception("Invalid viewstate key:" + str);
                  }

                  
      return Cache[str];
      #endif
              }
      2重载 SavePageStateToPersistenceMedium方法
      protected override void SavePageStateToPersistenceMedium(object viewState)
              
      {
                  
      string str = "VIEWSTATE#" + Session.SessionID.ToString() + "#" + DateTime.Now.Ticks.ToString();
                  
      //自动注册隐藏字段
                  RegisterHiddenField("__VIEWSTATE_KEY", str);
                  RegisterHiddenField(
      "__VIEWSTATE""");

                  
      if (_formatter == null)
                  
      {
                      _formatter 
      = new LosFormatter();
                  }


      #if VIEWSTATETOSQLSERVER
                  StringWriter _writer 
      = new StringWriter();
                  _formatter.Serialize(_writer, viewState);

                  
                  
      //$$$$$$$$$此处插入将viewstate写入数据库,需要提供参数:Request.Path,用户ID,SessionID,ViewState$$$$$$$$$
                  
      //如果操作失败,则从数据库中删除sessionID对应的所以记录
                  db.InsertSession(a,b,c,d);
      #else
                  Cache.Add(str, viewState, 
      null, DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero, CacheItemPriority.Default, null);
      #endif
              }

    • 页面存储机制(cache)(待续)

    • 异常处理(待续)

    • 页面皮肤(待续)

    • 数据访问机制(待续)

    • 代码安全机制(待续)

  • 相关阅读:
    apiClould微信三方登录,qq三方登录
    微信小程序 使用环信聊天工具
    某些控件的应用
    记事本(查找与替换)
    记事本部分功能
    Winform——计算器进制转换
    Winform——计算器
    汉企C#面向对象——继承Practice
    汉企C#面向对象——继承
    二分法
  • 原文地址:https://www.cnblogs.com/KUDO/p/490101.html
Copyright © 2011-2022 走看看