最近遇到的一些問題及發現

來源:互聯網
上載者:User

1.關於Server.UrlPathEncode和Server.UrlEncode的區別

Server.UrlPathEncode預設使用的是utf-8編碼而Server.UrlEncode預設為系統預設編碼(一般是gb2312)

Server.UrlDecode預設使用系統編碼解碼。所以這裡容易發生路徑解碼成亂碼的問題。

Response.Write(Server.UrlDecode(Server.UrlPathEncode("中文")) & "<hr>")
Response.Write(HttpUtility.UrlDecode(Server.UrlPathEncode("中文"), Encoding.UTF8) & "<hr>")

解決辦法: 解碼的地方使用utf-8編碼。HttpUtility.UrlDecode(Server.UrlPathEncode(String),  Encoding.UTF8);

              或者編碼的地方使用Server.UrlEncode(),編解碼的預設編碼方式都用gb2312;

2.關於Response.End()報thread終止的異常

當Response.End()語句放在try{}catch(){}中的時候就會出現這種問題;

解決辦法:

     將Response.End()放在try catch之外,如需要從try catch終止,可以使用return,然後在finally中使用Response.End();

3.TreeView控制項TreeView1_SelectedNodeChanged事件不觸發的問題

 TreeNode dir = new TreeNode(dw["pg_tag"].ToString(), dw["pg_id"].ToString());     

  root.ChildNodes.Add(dir);

但是當點擊父節點時,不觸發背景SelectedNodeChanged事件。

分析原因,可能是dopost函數有問題,再進一步分析,發現是頁面禁用了ViewState造成的。

解決辦法:

給要觸發選擇變更事件的節點添加動作

dir.SelectAction = TreeNodeSelectAction.SelectExpand;

頁面裡面啟用VeiwState  

<%@ Page Language="C#" AutoEventWireup="true" Inherits="left" EnableViewState="true" Codebehind="left.aspx.cs" %>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.