ASP和ASP.NET共用Cookies問題

來源:互聯網
上載者:User
1、asp.net操作Cookies方法:

Response.Cookies["tcpoauser"].Value=ds.Tables["Table"].Rows[0]["username"].ToString();
Request.Cookies["tcpoauser"].Value.ToString();

2、asp.net預設為utf-8編碼,asp為gb2312,所以彼此之間可以共用一個cookies,須把他們規定為相同的編碼。

asp.net 中,如果要修改輸出頁面的編碼,可以通過修改web.config中以下配置資訊

globalization requestEncoding="utf-8" responseEncoding="utf-8" />

以上只是修改整體的預設編碼,如果只有某個頁的編碼需要修改,ASP.net 中則可以簡單的使用下面代碼:

Encoding gb2312 = Encoding.GetEncoding("gb2312");Response.ContentEncoding = gb2312;

在非ASP.net 應用中,可能你讀到的資料是UTF-8編碼,但是你要轉換為GB2312編碼,則可以參考以下代碼:

 

string utfinfo = "document.write(/"alert('aa你好嗎??');/");";string gb2312info = string.Empty; Encoding utf8 = Encoding.UTF8;Encoding gb2312 = Encoding.GetEncoding("gb2312"); // Convert the string into a byte[].byte[] unicodeBytes = utf8.GetBytes(utfinfo);// Perform the conversion from one encoding to the other.byte[] asciiBytes = Encoding.Convert(utf8, gb2312, unicodeBytes); char[] asciiChars = new char[gb2312.GetCharCount(asciiBytes, 0, asciiBytes.Length)];gb2312.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);gb2312info = new string(asciiChars); 

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1623367

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.