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的名称和域名等信息了

  • 相关阅读:
    php使用iconv进行从utf8转为gb2312字符编码出错解决方案
    PHP 的 cURL库快速入门文档
    转载 DISCUZ!X1程序目录、文件列表及模板文件结构说明,帮助大家二级开发
    下拉菜单部分选项不允许选择
    Htaccess文件用法集锦
    MYSQL server has gone away解决办法
    Discuz X 模板中获取用户头像
    CSS Hack
    VS轻松保存重复多用的代码片段
    三菱FX PLC编程口通讯协议详解
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/3016759.html
Copyright © 2011-2022 走看看