日期:2014-05-16  浏览次数:20365 次

.NET中的ViewState通过Javascript解析以后中文是乱码。
.net中ViewState的值默认是在页面HTML源码中一段通过Base64编码的字符串,我在网络上找了个通过JavaScript解析Base64编码字符串的方法,但是其中的中文总是显示为乱码,不知道是什么原因?

以下是HTML页面的完全代码:
HTML code

<html>
    <head>
        <title>
                ViewState Decoder
        </title>
        <meta http-equiv="Content-Type" content="text/html" charset="utf-8">
    </head>
    <body>
        <font color="red">Please Paste the ViewState Value here:</font><br>
        <textarea id="txtEnCodeViewState" style="width:100%; height:200px;"></textarea>
        <input type="button" value="Decode ViewState" onclick="OnViewStateDecoderButton_Click();">
        <br><br>
        <font color="red">The Decode Result is:</font><br>
        <textarea id="txtDeCodeViewState" style="width:100%; height:200px;" readonly="true"></textarea>
        <script language="javascript">
        /**
         * 我在网上看到过很多BASE64的JavaScript算法,都觉得不满意,于是自己写了一个,在这里分享一下。
     * 我的代码在质量的效率都较高,没有一些冗余的操作。总体来讲我觉得非常不错。
     * 如果大家有什么不懂的地方可以问我。
     */
       var BASE64={
    /*x #xyeva{position:absolute; width:459px; height:281px; background-color:#fff; margin-left:-231px; padding:0px; z-index:99; top:100px; left:50%;}
 /*.tabborder {float:left; width:462px; height:285px;} */
 .tab {float:left; width:457px; height:279px; border: 1px solid #A5E3ED;} 
 .tabtitle{width:455px; height:28px; border:1px solid #FFF; background:url(http://www.cnblogs.com/images/cnblogs_com/amwggyy504/TabTitleBg.jpg) repeat-x left top; color:#0079BC; font-size:14px; line-height:28px;}
 .tabtitle img{float:right; margin:7px 10px 0 0;}
 .tabcontent{width:457px; height:248px; border-top:1px solid #A5E3ED; background:url(http://www.cnblogs.com/images/cnblogs_com/amwggyy504/TabContentBg.jpg) no-repeat left top;}
 .tabcontent ul{padding:20px 0; width:417px; margin-left:20px; *margin-left:0px; border-bottom:1px dotted #0079BC; text-align:left; line-height:20px; color:#0079BC;}
 .tabcontent li{padding:0 10px;}
 .tabcontent input{margin:0px 5px;}
 </style>
 <a href="#"   onclick="openEva();">弹出</a>
 <script language="javascript">
 function openEva(){
 var nav = new Navigator();
 nav.createWin();
 }
 var preObjects = null;
 var Navigator = function(id){
         this.id = id;
 };
 Navigator.initIndex = 0;
 Navigator.CONTAINER = "navigator";
 Navigator.prototype.createWin = function(){
         Mark.showHintDiv();
         var html = "";
         var container = document.createElement("DIV");
         container.id = Navigator.CONTAINER;
         html += "<div class='tabborder'>"
         html += "        <div class='tab'>"
         html += "                <div class='tabtitle'><ul><li style='float:left; padding-left:183px;'><strong>弹出框</strong></li><li style='float:right; width:20px;'><a href='javascript:Mark.close();'><img src='http://images.cnblogs.com/cnblogs_com/amwggyy504/TabTitleClose.jpg'></img></a></ul></div>"
         html += "                        <div class='tabcontent'>"
         html += "                                <ul><li>自定义显示的内容</li></ul>"
         html += "                                <ul><li>自定义显示的内容</li></ul>"
         html += "                        </div>"
         html += "                </div>"
         html += "</div>"
         container.innerHTML = html;