zoukankan      html  css  js  c++  java
  • Asp与Asp.net共用cookie

    asp直接写的cookie,asp.net无法直接读到,要重写一下,ASP代码如下:
    Response.Cookies("AdminName")=rs("username")
    Response.Write Request.Cookies("AdminName")

    第二行看起来有些多此一举,代码有些奇怪,不过这样写,asp.net的确可以正确读取到,asp.net中的代码如下:
    AdminName = Request.Cookies["AdminName"].Value.ToString();

    由于我传的值有可能是中文的,我试了一下中文,结果asp.net读取到是
    %D5%FE%D6%CE%B4%A6

    这也很简单啊,转一下就行了,结果用Server.UrlDecode转不过来,想起前一段写百度小偷程序时,一个代码转换方法;如下:
    System.Web.HttpUtility.UrlDecode(AdminName, System.Text.Encoding.GetEncoding(936));
    这样就可以获得正常的中文了;

    我把上面的思路整理一下;
    在ASP中写入cookie的方法是:
    Response.Cookies("cookie名称")="cookie的值"
    Response.Write Request.Cookies("cookie名称")


    那么在asp.net中读取时,包括读出中文:
    string cookie;
    cookie= Request.Cookies["cookie名称"].Value.ToString();
    cookie= System.Web.HttpUtility.UrlDecode(cookie, System.Text.Encoding.GetEncoding(936));

    我这里只写了asp写入cookie,asp.net读取的方法,没有写asp.net写入cookie,用asp读取;有机会再研究吧

  • 相关阅读:
    remove white space from read
    optimize the access speed of django website
    dowload image from requests
    run jupyter from command
    crawl wechat page
    python version 2.7 required which was not found in the registry windows 7
    health
    alternate rows shading using conditional formatting
    word
    【JAVA基础】static 关键字
  • 原文地址:https://www.cnblogs.com/scgw/p/2158352.html
Copyright © 2011-2022 走看看