views:

24

answers:

1

Hi all, so this is the scenario:

I have a base class for all login-controlled pages:

public class SessionControlledPage : Page
{
    protected virtual void Page_Load(Object sender, EventArgs e)
    {
        Response.AddHeader("Refresh", Convert.ToString(Session.Timeout * 60 + 5));
        if (Session.IsNewSession)
        {
            Response.Redirect("~/login.aspx");
        }
    }
}

And a regularpage.aspx page that inherints from the base class:

public partial class RegularPage : SessionControlledPage
{
    override protected void Page_Load(Object sender, EventArgs e)
    {
        base.Page_Load(sender, e);

        Server.Transfer("~/otherpage.aspx");
    }
}

Now let's say the original URL was http://localhost/regularpage.aspx and that Session.Timeout = 5. The problem appears when the refresh happens after the transfer takes place. I'm getting a 404 Not Found error and the URL changes for http://localhost/305. Notice that 5 * 60 + 5 = 305.

Do you know why is this happening? got a solution?

PD: I use transfer because I need to access some properties of regularpage.aspx on otherpage.aspx, maybe you could provide another solution for this too.

A: 

There is very little reason to call base.Page_Load if all you're going to do is then call Server.Transfer. What exactly are you trying to accomplish? If you're just accessing some properties you need to abstract this into some business logic that does not rely on the Page object.

This is also what is causing the 404 issue... for this to happen, the problem has to be in the rendered output of the page (check it out). It seems like you are cutting off one page right after the meta-refresh tag and then starting a new page and ASP.NET is just dumping it all into the same response stream. In short, you're doing it wrong. :) You might be able to fix this with a well-placed Response.Clear(), but that's not the real problem here... and you'd lose your refresh tag.

Bryan
thanks Bryan, actually the server.transfer() is not in the page_load is on another method (this is an example) and that method is called after a search is performed on the page and one result is clicked, I use the information associated with the link to pass it to the other page. I call base.Page_Load() because I'm overriding the Page_Load method from my base class, and also due to the order of execution on the pages life cycle, the code in the child Page_Load would execute before the Page_Load on the parent class, I need the parent Page_Load code to execute before not after.
Unlimited071
@Bryan could you please tell me more about the abstract business logic and how could I use it? I just need some simple info from the 'regular page' basically 3 integer codes. thanks.
Unlimited071
It's impossible to tell you how to do this without knowing what you're trying to do. But in general, any well-designed ASP.NET application is going to do as little as possible in the presentation layer code, and offload tasks into a business logic layer. 265 characters is not enough to explain this! Did you solve the original problem? You didn't respond about that...
Bryan
No, the problem persist.
Unlimited071