Hi,

I'm trying to redirect the admin user from my login.aspx page to the admin.aspx page and any other domain user to the default.aspx page. I have no problems getting the domain users redirecting or having a message displayed when the credentials are incorrect, however when I enter the admin details in the page doesn't redirect and just returns to the login.aspx page again. Is the something I'm doing wrong or is this not possible to have a user authenticate that isn't a domain user? My backend C# file is attached which shows what happens when the logon button is clicked.

Thanks

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void AuthenticateLogin(object sender, EventArgs e)
    {
        try
        {
            String _username = username_tb.Text;
            String _pasword = password_tb.Text;

            if (_username == "admin" && _pasword == "password")
            {
                Response.Redirect("admin/default.aspx");    
            }       

            else if (Membership.ValidateUser(_username, _pasword))
            {
                errors_bl.Items.Clear();
                Response.Write("Valid user");
                FormsAuthentication.RedirectFromLoginPage(_username, false);
                Response.Redirect("default/default.aspx");  
            }
            else
                {
                username_tb.Text = "";
                lblError.Visible= true;
                }

        }
        }

You should debug and see if the line Response.Redirect("admin/default.aspx"); is being executed.

If it is being executed, I'd guess that something on admin/default.aspx is redirecting back to the login.aspx.

Hi,

Thanks for the response. I created a new admin/default.aspx page with nothing in it like the code below and the redirect still wouldn't work, however renaming the default.aspx to default.html then adjusting the Response.Redirect to point to admin/default.html works. Do you know the reason why it won't redirect to an aspx page?

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>

</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.