是否可以在 ASP.NET Web 表单中使用 get 代替 post?
我有一个网站,设置为不时验证用户。每次验证用户时,用户都会被重定向到登录页面,这是 IIS 下的另一个 Web 应用程序。由于用户仍然有效,它将被重定向回来,但在此期间它已经丢失了回发数据,从而使整个表单设置为默认值。
我的第一个想法是关闭表单上的视图状态并使用 get 而不是表单标签上的 post get
<form runat="server" method="get" enableviewstate="false">...</form>
命令有效,但打印了获取视图状态的查询字符串,使得 url 很长。有什么简单的方法可以解决这个问题吗?基本上我想做的是完全关闭视图状态,我尝试使用enableviewstate
,但我无法让它消失。
I have a site that is set up to validate the user from time to time. Every time the user is validated the user is redirected to the login page, which is another web application under IIS. Since the user is still valid it will be redirected back, but during this time it has lost the postback data making the whole form set to default.
My first thought was to just turn off view state on the form and use get instead of post on the form tag
<form runat="server" method="get" enableviewstate="false">...</form>
The get command works, but the querystring get the view state is printed making the url to long. Is there some easy to solve this? Basically what I want to do is to turn off viewstate completely, I've tried to use the enableviewstate
, but I can't get it to dissapear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过在 web.config 中设置 enableViewState 属性,以便您得到如下所示的内容:
Have you tried setting the enableViewState property within web.config so you'd have something that looks like:
您可以使用 Grant 的建议在应用程序中禁用视图状态。或者,您可以在页面声明中针对单个页面将其关闭。例如:
You can disable viewstate across your application using Grant's suggestion. Alternatively, you could turn it off for a single page in the Page's declaration. For example:
标题与问题略有矛盾,因为您的实际问题似乎是,尽管您已设置
EnableViewState=False
您仍然将视图状态作为隐藏变量写入页面。这个问题是同样的,但即使使用这两种方法,您仍然会写入隐藏字段:
您自己的 PageStatePersister:
您自己的页面类,如链接的问题所描述:
所以您'剩下 jQuery:
The title contradicts the problem slightly, as it seems that your actual issue is that although you have set
EnableViewState=False
you are still getting the viewstate written to the page as hidden variables.This question is along the same lines, but you still get hidden fields written even if you use these two methods:
Your own PageStatePersister:
Your own page class, as the question linked describes:
So you're left with jQuery: