-1

我有一个要求,当 userA 登录时,我必须将 test1.aspx 显示为我的主页。当 userB 登录时,我必须显示 test2.aspx。我必须如何处理这种情况。请不要告诉我喜欢

if(userA) { response.redirect("abc.aspx"); }

4

3 回答 3

3

将您的用户放在下拉列表中并放置这样的条件...希望这对您有所帮助。

if (DropDownList1.Text == "管理员") {

            Response.Redirect("~/Admin/adminproduct.aspx");
        }
        else if (DropDownList1.Text == "TechSupport")
        {

            Response.Redirect("~/TechSupport/adminproduct.aspx");
        }
        else if (DropDownList1.Text == "Employee")
        {

            Response.Redirect("~/Employee/adminproduct.aspx");
        }
于 2013-07-01T11:21:37.710 回答
0

不知道你期待什么答案。您需要一些机制来根据某些标准确定将哪个页面发送给用户。无论哪种方式,它都会以类似于您作为示例“您不喜欢”的方式结束。我的建议是将用户分组并检查该组。

例如:

if (user.IsMemberOf("some group")
{
    // perform some steps and redirect
}
于 2013-07-01T10:18:11.830 回答
0

假设您有一个 Intranet(不是 Internet)网站:

protected void Page_Load(object sender, System.EventArgs e)
{
    // Request.ServerVariables["AUTH_USER"]
    // Request.ServerVariables["LOGON_USER"]
    // Request.ServerVariables["REMOTE_USER"]

    string str = this.Request.ServerVariables("LOGON_USER");
    Console.WriteLine(str);





    switch (str.ToLower()) {
        case "domain1\\username1":
            Response.Redirect("test1.aspx");
            break;
        case "domain1\\username2":
            Response.Redirect("test2.aspx");
            break;
        case "domain2\\username3":
            Response.Redirect("test3.aspx");
            break;
        default:
            throw new Exception("foo");
    }




}

如果您有 Internet 网站,则需要使用 ActiveX,这将限制您在 Windows 上使用 IE。

当然,如果您有可变数量的用户,那么您应该通过数据库来完成:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim str As String = Me.Request.ServerVariables("LOGON_USER")
        Response.Redirect(GetUrlForUserName(str))
End Sub

Public Shared Function GetUrlForUserName(strUserName As String) As String
    Dim strURL As String = ""

    Using conn As System.Data.Common.DbConnection = New System.Data.SqlClient.SqlConnection(GetConnectionString())

        If conn.State <> ConnectionState.Open Then
            conn.Open()
        End If

        Using cmd As System.Data.Common.DbCommand = conn.CreateCommand()
            cmd.CommandText = "SELECT URL FROM T_UserURLS WHERE UserName = @YOUR_USER_NAME"
            Dim para As System.Data.Common.DbParameter = cmd.CreateParameter()
            para.ParameterName = "@YOUR_USER_NAME"
            para.Value = strUserName
            para.DbType = DbType.AnsiString
            cmd.Parameters.Add(para)
            strURL = System.Convert.ToString(cmd.ExecuteScalar())
        End Using

        If conn.State <> ConnectionState.Closed Then
            conn.Close()
        End If

    End Using

    Return strURL
End Function



Public Shared Function GetConnectionString() As String
    Dim sb As New System.Data.SqlClient.SqlConnectionStringBuilder
    sb.DataSource = Environment.MachineName
    sb.InitialCatalog = "master"

    sb.IntegratedSecurity = True
    If Not sb.IntegratedSecurity Then
        sb.UserID = "YOUR_USER"
        sb.Password = "YOUR_PW"
    End If

    sb.PersistSecurityInfo = False
    sb.Pooling = False
    sb.PacketSize = 4096
    sb.MultipleActiveResultSets = True

    Return sb.ConnectionString
End Function
于 2013-07-01T10:24:22.573 回答