Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application that authenticate users against AD. I have an issue with user login on IIS. This is rather odd problem as everything works perfectly fine on development environment. If user credentials are wrong it will show popup indicating it is wrong in dev environment but when I host the application on IIS if user credentials are wrong that popup did not appear.

Here is my log in logic :

C#
try
            {
                Session["UserName"] = GWALogin.UserName;
                Session["Password"] = GWALogin.Password;
                TryLogin(GWALogin.UserName, GWALogin.Password);


            }
            catch (Exception _objEx)
            {
                GWALogin.FailureText = _objEx.Message;
                //lblError.Text = _objEx.Message;
                //lblError.Visible = true;
                GWALoginUpdatePanel.Update();

                errMessage.InnerText = _objEx.Message;
                updErrorMessage.Update();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ToggleScript", "window.setTimeout('open_errormessage_box()',500);", true);


            }

protected void TryLogin(string userid, string password)
        {
            try
            {
                Jardine.DTO.User objUser = new Jardine.DTO.User();
                
                string[] ValidADGroups;
                string allowedGorup;
                string strUserName = userid;
                string strPassword = password;
                bool blValidUser = false;
                string strDomainName =ConfigurationManager.AppSettings["Domain"].ToString();
                string strAdPath = ConfigurationManager.AppSettings["ADPath"].ToString();
                LdapAuthentication adAuth = new LdapAuthentication(strAdPath);

                //userRoleList = Roles.GetRolesForUser();
                if (adAuth.IsAuthenticated(strDomainName, strUserName, strPassword))
                {
                    ValidADGroups = adAuth.GetGroups(strDomainName , strUserName, strPassword);
                    allowedGorup = ConfigurationManager.AppSettings["ADGroup"].ToString();

                    for (int intCount = 0; intCount < ValidADGroups.Length; intCount++)
                    {
                        if (ValidADGroups[intCount].ToString() == allowedGorup)
                        {
                            blValidUser = true;
                            break;
                        }
                    }
                }
                if (blValidUser == true)
                {
                    objUser.UserName = userid;
                    objUser.Password = password;
                    Session["User"] = objUser;
                    Session["Division"] = ConfigurationManager.AppSettings["Division"].ToString();


                    FormsAuthenticationTicket tkt;
                    string cookiestr;
                    HttpCookie ck;
                    tkt = new FormsAuthenticationTicket(1, objUser.UserName, DateTime.Now,
                    DateTime.Now.AddMinutes(30), true, "Jardine");
                    cookiestr = FormsAuthentication.Encrypt(tkt);
                    ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);

                    ck.Path = FormsAuthentication.FormsCookiePath;
                    Response.Cookies.Add(ck);

                    string strRedirect;
                    strRedirect = "Home.aspx"; //Request["ReturnUrl"];

                   
                  
                    Response.Redirect(strRedirect, false);
                }
                else
                {
                    errMessage.InnerText = "Invalid UserName or Password!";
                    updErrorMessage.Update();
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ToggleScript", "window.setTimeout('open_errormessage_box()',500);", true);
                }


            }
            catch (Exception Ex)
            {
                throw Ex;
               
            }

        }


Interesting enough after sometime on IE it shows something is wrong with the page script and shows yellow exclamation at bottom left corner. If I double click it it shows below message : Point to note : I am authenticating user against AD and this page has no connection to database whatsoever. So I am not sure why it is saying "Unable to connect to SQL Server database." ?



Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Timestamp: Fri, 2 Mar 2012 00:18:29 UTC


Message: Sys.WebForms.PageRequestManagerServerErrorException: Unable to connect to SQL Server database.
Line: 4723
Char: 21
Code: 0
URI: http://revvg110:4455/ScriptResource.axd?d=tmzsU2Huftrx_UnzDAXJbcdfxQqfuhTMUgrqZnVrsIbQNjqD-OYfiiCHlWSAN-gWorCT2FdH5OI29Zltg1hXDQFhNc8JI2yvdrfiRLG4bMo1&t=ffffffff90822266


Any ideas ? I am really stumped here..
Posted
Updated 2-Mar-12 12:58pm
v2
Comments
Herman<T>.Instance 2-Mar-12 8:29am    
what's the code for TryLogin(GWALogin.UserName, GWALogin.Password);?
virang_21 2-Mar-12 18:58pm    
I have updated the question.
ZurdoDev 7-Mar-12 11:31am    
The error says it cannot connect to SQL server. That should be pretty easy to track down.
virang_21 7-Mar-12 14:58pm    
Hi Ryan, The big question mark is I don't have any database related connection on that page... Apart from that it works perfectly fine in development environment... I am validating users against AD nothing to do with database....

1 solution

missed to add this bit to web.config file. Finally solved the issue.

XML
<membership defaultprovider="MyADMembershipProvider">
     <providers>
       <clear />
       <add name="MyADMembershipProvider">
       type="System.Web.Security.ActiveDirectoryMembershipProvider,System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
       attributeMapUsername="sAMAccountName"
       connectionStringName="ADConnectionString"/>
     </add></providers>
   </membership>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900