【发布时间】:2022-01-06 18:18:37
【问题描述】:
我的站点有default.aspx 页面,您单击提交并进入customerinfo.aspx 页面。但是,它们必须来自同一域中的 default.aspx 页面。如果引用者为空、外部链接或他们的客户 ID 不存在,则它会重定向回 default.aspx 页面,以便他们可以输入他们的信息,否则它会在 customerinfo.aspx 页面上显示客户的数据。试图阻止从外部 URL 访问该页面,如果您这样做但只需要重定向到默认页面,它会显示对象引用错误。
Uri referrer = HttpContext.Current.Request.UrlReferrer;
if (referrer == null || string.IsNullOrEmpty(Request.UrlReferrer.ToString()) && string.IsNullOrEmpty(Session["customerID"].ToString()))
{
//This section is skipped because it's not a null referrer.
Response.Redirect(url: "default.aspx", endResponse: false);
return;
}
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(Request.QueryString["customerID"]))
{
//This section is skipped even though there's a customer ID?
Session["customerID"] = Request.QueryString["customerID"];
customerInfo();
}
else
{
if (string.IsNullOrEmpty(Session["customerID"].ToString()))
{
//This section is skipped because it's not an empty session, there's a customer ID.
Response.Redirect(url: "default.aspx", endResponse: false);
}
else
{
//This section is hit because there's a customer ID so the string isn't empty but not sure why the first isn't hit?
customerInfo();
}
}
}
【问题讨论】:
-
请提出一个明确的问题,因为不清楚您想要回答什么。
-
您应该考虑到有人可以在这里伪造引荐来源网址(您将阻止“深层链接”但不一定从外部访问)...但是您在服务器上做的事情会更容易-config 级别...也许可以看到这个帖子:stackoverflow.com/questions/66437496/…
-
我更新了@jesse-johnson 的问题。
-
好的,我现在检查那个链接。谢谢@pcalkins。