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

  • 相关阅读:
    github访问慢
    vue的图片裁剪上传vue-cropper
    vue动态设置路由重定向
    vue移动端预览pdf
    Vue项目中给路由跳转加上进度条nprogress
    IDEA收藏夹迁移
    Go语言基础语法(一)
    Go语言开发环境安装
    Windows上实现iOS APP自动化测试:tidevice + WDA + facebook-wda / appium
    配置Linux主机名
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/3016759.html
Copyright © 2020-2023  润新知