指定了其他页面时,重定向到Web应用程序的默认文档? [英] Redirect to webapp default document when another page is specified?

查看:199
本文介绍了指定了其他页面时,重定向到Web应用程序的默认文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IIS6,ASP.NET 2.0,无窗体身份验证

IIS6, ASP.NET 2.0, No Forms Authentication

我打电话的Response.Redirect(〜/ foo.aspx),但我的网站的默认文档(Default.aspx的)正在出现。更糟糕的是,它只是发生间歇性。有时重定向显示正确的页面。

I'm calling Response.Redirect("~/foo.aspx"), but the default document ("Default.aspx") for my site is appearing. To make matters worse, it only happens intermittently. Sometimes the redirect displays the right page.

我检查会话状态,我没有看到在web.config中的任何值(即我假设我用20分钟的默认值)。

I've checked session state, and I don't see any values in the web.config (that is, I'm assuming I'm using the 20-minute defaults).

我希望我有更多的相关信息分享(我会尽我所能回答任何问题)。

I wish I had more relevant information to share (I'll do my best to answer any questions).

任何想法?为什么是不是重定向到指定的页面?

Any ideas? Why isn't it redirecting to the specified page?

编辑:我看了deeeeeper到code和了解到更多的细节。

I've looked deeeeeper into the code and learned more details.

确定。有foo.aspx和foo2.aspx(和默认文档,Default.aspx的)。所有页从的BasePage,它扩展页扩展。

Ok. There's foo.aspx and foo2.aspx (and the default document, Default.aspx). All pages extend from BasePage, which extends Page.

的BasePage有一个名为ReturnPage属性:

BasePage has a property named ReturnPage:

protected string ReturnPage {
    get {
        if (Session["ReturnPage"] == null) {
            Session["ReturnPage"] = "";
        }
        return Session["ReturnPage"].ToString();
    }
    set { Session["ReturnPage"] = value; }
}

用户点击上foo.aspx一个LinkBut​​ton,然后单击事件处理程序code两行结尾:

Users click on a LinkButton on foo.aspx, and the click event handler ends with two lines of code:

ReturnPage = ResolveUrl("~/foo.aspx");
Response.Redirect(ResolveUrl("~/foo2.aspx"));

foo2.aspx的Page_Load中有问题,它的错误处理调用的Response.Redirect(ReturnPage)。

The Page_Load of foo2.aspx has problems, and its error handling calls Response.Redirect(ReturnPage).

当我查看foo2.aspx的响应头,302位置的String.Empty(即,没有之一)。同样的响应头具有相同的ASP.NET会话ID作为foo.aspx的响应。

When I view the response headers of foo2.aspx, the 302 location is string.Empty (that is, there isn't one). That same response header has the same ASP.NET Session ID as the response of foo.aspx.

和记住 - 这是间歇性的。有时候,你可以点击该LinkBut​​ton的去不费吹灰之力就foo2.aspx,没有问题。可以处理具有完全相同的数据的点击一次,并且将失败。你会从默认文档(Default.aspx的,在那里你被虫送)回foo.aspx导航,使用相同的数据再次单击(在同一行中网格/表 - 同样的LinkBut​​ton,本质上),你会被重定向没有问题foo2.aspx。

And remember -- this is intermittent. Sometimes, you can click on that LinkButton and go effortlessly to foo2.aspx, no problem. You can process the click with the exact same data once, and it will fail. You'll navigate from the default document (Default.aspx, where you were sent by the "bug") back to foo.aspx, click again with the same data (the same row in the grid/table -- the same LinkButton, essentially), and you'll be redirected to foo2.aspx without issue.

推荐答案

<一个href=\"http://weblogs.asp.net/bleroy/archive/2004/08/03/Don_2700_t-redirect-after-setting-a-Session-variable-_2800_or-do-it-right_2900_.aspx\"相对=nofollow>立即的Response.Redirect()之前放置在会话中的值是有风险的。

更改foo.aspx的Response.Redirect的()以下可能保留更可靠的会话值:

Changing foo.aspx's Response.Redirect() to the following might retain the session value more reliably:

Response.Redirect("~/foo2.aspx", false);

更新:这结束了​​只有把我们的会话状态到SQL Server是固定的。请参阅相关的问题:<一href=\"http://stackoverflow.com/questions/2267818/why-when-are-session-writes-vulnerable-to-thread-termination\">Why/when在会话写入易受线程终止?

UPDATE: This ended up being fixed only by moving our session state into SQL Server. See related question: Why/when are session writes vulnerable to thread termination?

这篇关于指定了其他页面时,重定向到Web应用程序的默认文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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