访问__VIEWSTATE&安培; __EVENTVALIDATION在C# [英] Access __VIEWSTATE & __EVENTVALIDATION in C#

查看:330
本文介绍了访问__VIEWSTATE&安培; __EVENTVALIDATION在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET ,是有可能得到__VIEWSTATE和__EVENTVALIDATION值隐藏字段成C#(服务器端)的一个变量,比方说,重写渲染方法?

In ASP.NET, is it possible to get the values of __VIEWSTATE and __EVENTVALIDATION hidden fields into a variable in C# (server side) in, let's say, overriding the Render method?

我曾尝试:

protected override void Render(HtmlTextWriter writer)
{
    StringBuilder stringBuilder = new StringBuilder();
    StringWriter stringWriter = new StringWriter(stringBuilder);
    HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

    base.Render(htmlWriter);
    string temp = stringBuilder.ToString();
}

这给了我整个ASP.NET输出。我们可以用一个字符串函数得到的值,但我并没有觉得这是一个很干净的解决方案。有没有更好的方式来做到这一点?

This gives me the entire ASP.NET output. We can get the values by using a string function, but I did not find it a very clean solution. Is there a better way to do this?

什么其实我是想为__VIEWSTATE和放大器的价值; __EVENTVALIDATION当第一请求是由与不回传完成之后。当如果第一请求时形成的输出流即

What I actually want is the values of __VIEWSTATE & __EVENTVALIDATION when the first request is made and not after the postback is done. That is when the output stream if formed when the first request is made.

推荐答案

如果您使用反射看类,你会看到在创建这些隐藏字段呈现阶段(看方法 RenderViewStateFields EndFormRenderHiddenFields )。

If you look at the Page class using Reflector, you'll see these hidden fields are created during the render phase (look at the methods RenderViewStateFields and EndFormRenderHiddenFields).

您也许可以得到一些/全部采用反射数据(例如内部属性 Page.ClientState )。

You could probably get at some/all of the data using reflection (e.g. the internal property Page.ClientState).

但我不认为这是一个干净的解决方案(虽然说实话我真的不明白你想达到什么目的)。

But I don't think there is a clean solution (though to be honest I don't really understand what you're trying to achieve).

这篇关于访问__VIEWSTATE&安培; __EVENTVALIDATION在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆