如何在VS调试器中浏览我的页面ViewState的内容?

发布于 2024-12-04 06:25:29 字数 191 浏览 4 评论 0原文

我有一个经常使用的 ASP.net 网页。问题是 ViewState 变得巨大!该页面有一个具有分页和排序功能的 ASP.net GridView。然而,ViewState 的大小似乎与页面上的内容完全不成比例。

我想知道如何在Visual Studio 2010调试器中浏览ViewState的内容,以便我可以知道ViewState中保存了哪些数据。

I have an ASP.net web page that is heavily used. The problem is that the ViewState is becoming huge! The page has an ASP.net GridView with paging and sorting. However, the size of the ViewState seems totally out of proportion with what's on the page.

I would like to know how to browse the contents of the ViewState in the Visual Studio 2010 debugger so that I can know what data is being saved in the ViewState.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋心╮凉 2024-12-11 06:25:29

我不确定它是否适合您的需求,但您可以查看此工具:

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

这是您查看的帮助程序类,它将 ViewState 的内容转储到日志中 文件。显然,您可以根据需要对其进行修改。

// 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

I'm not sure if it will suit your needs, but you can check out this tool:

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

And here's helper class you check out which dumps the contents of the ViewState to a log file. Obviously, you can modify it as needed.

// 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));
    }
}

And you can call it like this:

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

See this link for more details:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文