0

我正在使用会话将值从发送页面发送到接收页面,它工作正常,但问题是我记得URL,我直接运行接收页面,它显示以前的信息,但它是无效的......?

如果最终用户直接访问接收页面,我需要限制或提供类似的消息

我该如何克服这个问题............

这是我的代码

发送.aspx.cs

protected void gv_rowcommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        GridViewRow grow = (GridViewRow)(((LinkButton)e.CommandSource)).NamingContainer;

        Session["c"] = grow.Cells[0].Text;
        Session["s"] = grow.Cells[1].Text;
        Session["e"] = grow.Cells[2].Text;
        Session["t"] = grow.Cells[3].Text;
        Session["a"] = grow.Cells[4].Text;
        Response.Redirect("confirmation.aspx");

    }   
}

确认.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    lblgetcourse.Text = Convert.ToString(Session["c"]);
    lblgetstartdate.Text = Convert.ToString(Session["s"]);
    lblgetenddate.Text = Convert.ToString(Session["e"]);
    lblgettimings.Text = Convert.ToString(Session["t"]);
    lblgetamount.Text = Convert.ToString(Session["a"]);
}
4

4 回答 4

2

在确认页面上显示值后,您可以将它们从会话中删除。

Session.Remove("c");
...

这将确保确认页面将始终显示来自该页面的send.aspx值。您还可以在显示之前检查会话中是否存在这些值。

于 2013-10-29T08:16:20.600 回答
1

On Confirmation Page, Fetch the Values from Session Variables an display them , then Clear Session variables just like: Session.Clear();

于 2013-10-29T08:19:40.433 回答
0

You can check the referrer header :

Request.UrlReferrer

and see where the request comes from.

so your page_load will look like :

protected void Page_Load(object sender, EventArgs e)
{
  if (!Request.UrlReferrer=='...') Response.Redirect("~/login.aspx");
...
于 2013-10-29T08:18:37.540 回答
0
protected void Page_Load(object sender, EventArgs e)
{
    if(Request.UrlReferrer.AbsolutePath == "~/send.aspx")
    {
        lblgetcourse.Text = Convert.ToString(Session["c"]);
        lblgetstartdate.Text = Convert.ToString(Session["s"]);
        lblgetenddate.Text = Convert.ToString(Session["e"]);
        lblgettimings.Text = Convert.ToString(Session["t"]);
        lblgetamount.Text = Convert.ToString(Session["a"]);
    }
    else
    {
        //do something
    }

}
于 2013-10-29T08:19:11.183 回答