在页面 1 中单击按钮时,我使用 msgid 将页面重定向到页面 2,在页面加载的页面 2 中,我检查上一页是否有效。所以我检查了 (this.Page.PreviousPage != null)
但这始终为 null,页面被重定向到第 1 页。我这样做是为了让任何人都无法更改 url 中的 msgid。我该如何解决这个问题。谢谢
第 1 页:
int msgid = Convert.ToInt32(Hidden_MsgID.Value);
string url = "Page2.aspx?MsgID=" + msgid;
Response.Redirect(url);
第 2 页:
if (this.Page.PreviousPage != null)
{
}
else
{
Response.Redirect("Page1.aspx");
}
我使用的不是 response.redirect server 。转移并且有效 Server.Transfer(string.Format("ResponseMetric.aspx?MsgID={0}", msgid));
最佳答案
PreviousPage
仅适用于 Server.Transfer
和/或跨页发布:http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage.aspx
可用的解决方案元素 here : 使用 this.Request.UrlReferrer
关于c# - 如何检查页面是否从上一页重定向或不在 asp.net 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8834563/