Redirect to webapp default document when another page is specified?

本小妞迷上赌 提交于 2019-12-01 11:05:23
lance

Placing a value in the session immediately before a Response.Redirect() is risky.

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

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

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?

When you say:

Sometimes the redirect displays the right page.

Does it just happen, and you are not sure if there are certain pages that are affected by the problem? If this is the case, then you probably have a addressing problem. You can use either a relative path or an absolute path rather than an Application-relative path. I would also guess that you are trying to either direct to a page from a subdirectory on your site or to a subdirectory on your site. If you choose to stick with the Application-relative path make sure that are taking the subdirectory into account. (ex: ~/FooPages/Foo.aspx)

Here is a good reference page I just found: http://nathanaeljones.com/129/types-of-asp-net-paths/

I'm a little confused here. What exactly are you trying to accomplish? You're getting the default document exactly because the 302 is blank. Your "inconsistent" behavior is almost certainly due to the way you are saving data in the Session.

The real issue here is why you're redirecting when foo2.aspx "has problems". What's the problem here? Why redirect? If you really need to redirect, why is the redirect target changed? Make it a static error reporting page and you'll be fine.

Once you redirect and get a new instance of the BasePage from foo2.aspx, won't that ReturnPage property be null again? Then once your page load errors out and tries to redirect it will be accessing a null string. Maybe try throwing that property in the Session

Session.Add("ReturnPage","~/foo.aspx") 

instead of

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

Ofcourse you would have to modify that error handling in the page load to grab it out of session rather than the property and you may have to rethink how the whole redirect is working in your system if this turns out to be the issue.

EDIT: To test this idea about the property not getting set, or getting set correctly....(just to test I am not suggesting you should hard code the path in there), change your getter to the example below, then check to see if it works. Hope this helps, I am curious to find out what the problem is if this is not the issue.

get { 
   if (Session["ReturnPage"] == null) { 
        Session["ReturnPage"] = "~/foo.aspx"; 
    } 
    return Session["ReturnPage"].ToString(); 

} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!