2011-09-13 3 views
0

私は、ASP.netのWebページを頻繁に使用しています。問題は、ViewStateが巨大になっていることです!ページにはページングとソートを持つASP.net GridViewがあります。しかし、ViewStateのサイズは、ページ上のものとはまったく比例しているようです。私のページの内容をVSデバッガのViewStateでブラウズするには?

Visual Studio 2010デバッガでViewStateの内容を参照して、どのデータがViewStateに保存されているかを知る方法を知りたいと思います。

+0

は本当に私ができるように、個々のViewStateのメンバにアクセスする方法はありませんアプリケーション変数またはセッション変数を使用していますか? –

答えて

0

私はそれはあなたのニーズに合うかどうかわからないんだけど、あなたは、このツールをチェックアウトすることができます:あなたがログにViewStateの内容をダンプしているかをチェックするヘルパークラス

http://www.pluralsight-training.net/community/media/p/51688.aspx

そして、ここですファイル。明らかに、必要に応じて変更することができます。

// Written by Greg Reddick. http://www.xoc.net 
public static void SeeViewState(string strViewState, string strFilename) 
{ 
    if (strViewState != null) 
    { 
     Debug.Listeners.Clear(); 
     System.IO.File.Delete(strFilename); 
     Debug.Listeners.Add(new TextWriterTraceListener(strFilename)); 

     string strViewStateDecoded = (new System.Text.UTF8Encoding()).GetString(Convert.FromBase64String(strViewState)); 

     string[] astrDecoded = strViewStateDecoded.Replace("<", "<\n").Replace(">", "\n>").Replace(";", ";\n").Split('\n'); 
     Debug.IndentSize = 4; 

     foreach (string str in astrDecoded) 
     { 
      if (str.Length > 0) 
      { 
       if (str.EndsWith("\\<")) 
       { 
        Debug.Write(str); 
       } 
       else if (str.EndsWith("\\")) 
       { 
        Debug.Write(str); 
       } 
       else if (str.EndsWith("<")) 
       { 
        Debug.WriteLine(str); 
        Debug.Indent(); 
       } 
       else if (str.StartsWith(">;") || str.StartsWith(">")) 
       { 
        Debug.Unindent(); 
        Debug.WriteLine(str); 
       } 
       else if (str.EndsWith("\\;")) 
       { 
        Debug.Write(str); 
       } 
       else 
       { 
        Debug.WriteLine(str); 
       } 
      } 
     } 

     Debug.Close(); 
     Debug.Listeners.Clear(); 

     //Get into the debugger after executing this line to see how .NET looks at 
     //the ViewState info. Compare it to the text file produced above. 
     Triplet trp = (Triplet) ((new LosFormatter()).Deserialize(strViewState)); 
    } 
} 

そして、あなたはこのようにそれを呼び出すことができます。

DebugViewState.SeeViewState(Request.Form("__VIEWSTATE"), "c:\temp\viewstate.txt") 

詳細はこちらのリンクを参照してください:

http://www.xoc.net/works/tips/viewstate.asp

+0

答えをありがとう。残念ながら、私のviewstate(それはいくつかの生のHTMLが含まれているようです)でそれを実行すると、あなたのコードは例外をスローします。私は何が分かるかを見ていきます。 –

関連する問題