如何在使用查询参数时仅允许特定用户访问特定页面,例如...?id = 3

时间:2012-11-01 15:58:15

标签: asp.net membership

我有一个页面,根据请求中的id参数显示一些数据。

用户必须登录

如何阻止用户访问属于其他用户的某些ID。重定向是最佳选择吗?

1 个答案:

答案 0 :(得分:0)

您可以在呈现页面之前检查服务器端,然后重定向...等:

void Page_Load(object sender, EventArgs e)
{    
    string bla = Request["key"] != null ? Request["key"] : "";
    if(String.IsNullOrEmpty(bla))
    if (bla=="yourvaluetocheck" && !User.IsInRole("theroletouse"))
    {
        Response.Redirect("~/permissiondenied.aspx");
    }
}

这是一个非常简单的例子,我会将这种类型的逻辑放在我的应用程序的中心位置以便重复使用。