简体   繁体   中英

login page not redirecting to main page in iis server asp.net c#

Here is the c# coding using for login and main page redirection:

try
{
    db = new DBFunctions();
    string mSQL = ("SELECT COUNT(username) FROM [User] WHERE LTRIM(RTRIM(username))='" + (txtusername.Text) + "'");
    db.Initialize("Text", mSQL);
    int mcount = Convert.ToInt32(db.cmd.ExecuteScalar());
    if (mcount == 1)
    {
        string mSQL1 = ("SELECT COUNT(username) FROM [User] WHERE LTRIM(RTRIM(username))='" + (txtusername.Text) + "'");
        db.Initialize("Text", mSQL);
        int mcount1 = Convert.ToInt32(db.cmd.ExecuteScalar());
        if (mcount1 == 1)
        {
            Response.Redirect("dash.aspx", false);
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Password Wrong.! Please Contact IT (377)')", true);
        }

    }
    else
    {
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Username and Password does not match Please Contact IT (377)')", true);
    }
}
catch (Exception ex)
{
    //Response.Write("<script>alert('"+ex.Message+"');</script>");
}

This above code works fine in localhost environment but if host in iis server it is not redirect to main page (if i click login button it just stay on login page ).

Localhost is not a server so in this case there might be a lot of reason to not work that your code. I think you are getting an exception and you are not catching it. I'll suggest to uncomment your code in catching exception and see that.

You May need to install/setup httpRedirect.

Kindly go through the below link for the more information.

http://www.iis.net/configreference/system.webserver/httpredirect

I hope it should work.

Thanks

i used the following line in web.config file

<identity impersonate="true" userName="domain\username" password="password"/>

this solved my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM