zoukankan      html  css  js  c++  java
  • Forms表单登陆,动态获取web.config里面的cookies配置

    image

    以前写死的写法是

     1:  //设置登录权限
     2:                  HttpCookie cook;
     3:   
     4:                  string roles = "admin";//用户角色
     5:  
     6:                  FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
     7:   
     8:                  1, tid, DateTime.Now, DateTime.Now.AddMinutes(600), true, roles);
     9:   
    10:                  cook = new HttpCookie(".xxxxCookie");
    11:                  cook.Domain = ".youxxxxx.com";
    12:                  cook.Value = FormsAuthentication.Encrypt(ticket);
    13:   
    14:                  Response.Cookies.Add(cook);
    15:                  //权限结束
    16:  

    动态读取的写法是

     1:  //设置登录权限
     2:                  HttpCookie cook;
     3:   
     4:                  string roles = "admin";//用户角色
     5:  
     6:                  FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
     7:   
     8:                  1, tid, DateTime.Now, DateTime.Now.AddMinutes(600), true, roles);
     9:   
    10:                  AuthenticationSection authen = WebConfigurationManager.GetSection("system.web/authentication") as AuthenticationSection;
    11:                  string cookName = authen.Forms.Name;
    12:                  string cookDomain = authen.Forms.Domain;
    13:                  cook = new HttpCookie(cookName); //".xxxxCookie"
    14:                  cook.Domain = cookDomain;   //.youxxxx.com
    15:                  cook.Value = FormsAuthentication.Encrypt(ticket);
    16:   
    17:                  Response.Cookies.Add(cook);
    18:                  //权限结束
    19:  

    动态读取的好处就是,你修改了web.config里面的配置,我就不用去登陆界面修改cookies的名称和域名等信息了

  • 相关阅读:
    (转)Zipalign——Android apk优化工具
    (转)Android 数字证书详
    (转)ant深入浅出
    (转)Java调用Ant API用法
    (转)Java 代码调用ANT
    (转) Android如果对APK进行加密,提高反编译难度(思路)
    (转)Ant自动打包
    (转)Ant build.xml中的各种变量,使用系统环境变量
    (转)JAVA调用脚本
    (转)Android 编译,打包、签程名详细教
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/3016759.html
Copyright © 2011-2022 走看看