在ASP中可以用get代替post吗?净webforms吗?

时间:2022-05-05 08:09:28

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.

我有一个站点,它是用来不时地验证用户的。每次验证用户时,用户都被重定向到登录页面,这是IIS下的另一个web应用程序。由于用户仍然有效,它将被重定向回,但是在这段时间内,它丢失了回发数据,使整个表单设置为默认。

My first thought was to just turn off view state on the form and use get instead of post on the form tag

我的第一个想法是关闭窗体上的视图状态,使用get而不是在窗体标记上粘贴

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

get命令可以工作,但是querystring get视图状态被打印,使url变为long。有什么容易解决的吗?基本上我要做的就是完全关闭viewstate,我尝试过使用enableviewstate,但是我不能让它消失。

3 个解决方案

#1


2  

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:

您可以使用Grant的建议在整个应用程序中禁用viewstate。或者,您可以关闭页面声明中的一个页面。例如:

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" EnableSessionState="ReadOnly" %>

#2


2  

Have you tried setting the enableViewState property within web.config so you'd have something that looks like:

您是否尝试过在web中设置enableViewState属性。配置,这样你就会得到如下的效果:

<pages enableViewState="false">
    ....
</pages>

#3


-1  

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.

标题稍微反驳了这个问题,因为看起来您的实际问题是,尽管您已经设置了EnableViewState=False,但是您仍然将viewstate作为隐藏变量写入页面。

This question is along the same lines, but you still get hidden fields written even if you use these two methods:

这个问题是沿着同样的思路,但是即使你使用这两种方法,你仍然会得到隐藏字段:

Your own PageStatePersister:

你自己的PageStatePersister:

public class EmptyStatePersister : PageStatePersister
{
    public EmptyStatePersister(Page page) : base(page) { }
    public override void Load() { }
    public override void Save() { }
}

protected override PageStatePersister PageStatePersister
{
    get
    {
        return new EmptyStatePersister(this);
    }
}

Your own page class, as the question linked describes:

您自己的页面类,如链接的问题所描述:

public class EmptyViewStatePage : Page
{
    public override bool EnableViewState
    {
        get
        {
            return false;
        }
        set
        {
            base.EnableViewState = false;
        }
    }

    protected override void SavePageStateToPersistenceMedium(object state)
    {

    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        return null;
    }
}

So you're left with jQuery:

剩下jQuery:

<script type="text/javascript">
    $(document).ready(function ()
    {
        $("#__EVENTVALIDATION").remove();
        $("#__VIEWSTATE").remove();
    });
</script>

#1


2  

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:

您可以使用Grant的建议在整个应用程序中禁用viewstate。或者,您可以关闭页面声明中的一个页面。例如:

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" EnableSessionState="ReadOnly" %>

#2


2  

Have you tried setting the enableViewState property within web.config so you'd have something that looks like:

您是否尝试过在web中设置enableViewState属性。配置,这样你就会得到如下的效果:

<pages enableViewState="false">
    ....
</pages>

#3


-1  

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.

标题稍微反驳了这个问题,因为看起来您的实际问题是,尽管您已经设置了EnableViewState=False,但是您仍然将viewstate作为隐藏变量写入页面。

This question is along the same lines, but you still get hidden fields written even if you use these two methods:

这个问题是沿着同样的思路,但是即使你使用这两种方法,你仍然会得到隐藏字段:

Your own PageStatePersister:

你自己的PageStatePersister:

public class EmptyStatePersister : PageStatePersister
{
    public EmptyStatePersister(Page page) : base(page) { }
    public override void Load() { }
    public override void Save() { }
}

protected override PageStatePersister PageStatePersister
{
    get
    {
        return new EmptyStatePersister(this);
    }
}

Your own page class, as the question linked describes:

您自己的页面类,如链接的问题所描述:

public class EmptyViewStatePage : Page
{
    public override bool EnableViewState
    {
        get
        {
            return false;
        }
        set
        {
            base.EnableViewState = false;
        }
    }

    protected override void SavePageStateToPersistenceMedium(object state)
    {

    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        return null;
    }
}

So you're left with jQuery:

剩下jQuery:

<script type="text/javascript">
    $(document).ready(function ()
    {
        $("#__EVENTVALIDATION").remove();
        $("#__VIEWSTATE").remove();
    });
</script>