Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 登录MyWSAT后重定向_Html_Asp.net_Asp.net Membership - Fatal编程技术网

Html 登录MyWSAT后重定向

Html 登录MyWSAT后重定向,html,asp.net,asp.net-membership,Html,Asp.net,Asp.net Membership,我一直在这里测试示例代码 在他们的示例中,他们使用不同的按钮登录到管理页面或成员页面,使用不同的链接 但是,我尝试使用一个指向登录页面的链接,在用户登录后,使用codebehind重定向到相关页面。登陆页面需要登录,但所有角色都可以查看规则中设置的此页面 landingpage.aspx: protected void Page_Load(object sender, EventArgs e) { string redirectPath; string p

我一直在这里测试示例代码

在他们的示例中,他们使用不同的按钮登录到
管理
页面或
成员
页面,使用不同的链接

但是,我尝试使用一个指向登录页面的链接,在用户登录后,使用codebehind重定向到相关页面。登陆页面需要登录,但所有角色都可以查看规则中设置的此页面

landingpage.aspx:

protected void Page_Load(object sender, EventArgs e)
    {
        string redirectPath;
        string pagePath = Request.AppRelativeCurrentExecutionFilePath;
        if (Page.User.IsInRole("Administrator"))
        {
            //Admin
            redirectPath = "~/admin/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
        else if (Page.User.IsInRole("Member"))
        {
            //Members
            redirectPath = "~/members/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
        else if (Page.User.IsInRole("Trial"))
        {
            //Trial
            redirectPath = "~/trial/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
        else
        {
            //Non member
            redirectPath = "~/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
    }
       // Next, determine if the user's username/password are valid
        if (Membership.ValidateUser(loginUsername, loginPassword))
        {
            e.Authenticated = true;
            //tried redirecting from here based on role!
        }
        else
        //............
问题是Page_Load事件会立即触发,然后在触发事件后启动带有captcha.ascx的登录

因此,我将代码移动到登录表单
login with captcha.ascx.cs
以在
e.Authenticated=true之后重定向
但它只是在一个无休止的循环中重定向回使用captcha.ascx登录的

使用captcha.ascx.cs登录:

protected void Page_Load(object sender, EventArgs e)
    {
        string redirectPath;
        string pagePath = Request.AppRelativeCurrentExecutionFilePath;
        if (Page.User.IsInRole("Administrator"))
        {
            //Admin
            redirectPath = "~/admin/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
        else if (Page.User.IsInRole("Member"))
        {
            //Members
            redirectPath = "~/members/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
        else if (Page.User.IsInRole("Trial"))
        {
            //Trial
            redirectPath = "~/trial/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
        else
        {
            //Non member
            redirectPath = "~/Default.aspx";
            if (redirectPath != pagePath)
            {
                Response.Redirect(redirectPath);
            }
        }
    }
       // Next, determine if the user's username/password are valid
        if (Membership.ValidateUser(loginUsername, loginPassword))
        {
            e.Authenticated = true;
            //tried redirecting from here based on role!
        }
        else
        //............

验证用户后,如何从登录页重定向?我怀疑这可能与回发有关,但需要一些帮助

能否尝试在页面加载的第一行添加以下内容以查看是否有帮助?这可能会防止无休止的循环问题,如果它是由触发回发事件的事件(如按钮单击)引起的

if (IsPostBack) return;

您能否尝试在页面加载中添加以下内容作为第一行,看看是否有帮助?这可能会防止无休止的循环问题,如果它是由触发回发事件的事件(如按钮单击)引起的

if (IsPostBack) return;