IIS上的登录控制出了点问题 [英] Something wrong with login control on IIS

查看:70
本文介绍了IIS上的登录控制出了点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以根据AD对用户进行身份验证的应用程序.我在IIS上的用户登录有问题.这是一个相当奇怪的问题,因为在开发环境上一切都可以正常工作.如果用户凭据错误,则会显示弹出窗口,表明在开发环境中是错误的,但是当我在IIS上托管应用程序时,如果用户凭据错误,则不会出现弹出窗口.

这是我的登录逻辑:

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 :

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;
               
            }

        }



在IE上运行一段时间后,很有趣,它显示页面脚本有问题,并且在左下角显示黄色惊叹号.如果我双击它,它将显示以下消息:注意:我正在根据AD对用户进行身份验证,并且此页面与数据库均没有任何关系.因此,我不确定为什么会说无法连接到SQL Server数据库". ?



网页错误详细信息

用户代理:Mozilla/4.0(兼容; 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)
时间戳记:2012年3月2日,星期五,00:18:29 UTC


消息:Sys.WebForms.PageRequestManagerServerErrorException:无法连接到SQL Server数据库.
线:4723
字符:21
代码:0
URI:http://revvg110:4455/ScriptResource.axd?d = tmzsU​​2Huftrx_UnzDAXJbcdfxQqfuhTMUgrqZnVrsIbQNjqD-OYfiiCHlWSAN-gWorCT2FdH5OI29Zltg1hXDQFhNc8&2;

有任何想法吗 ?我真的很困惑..



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..

推荐答案

缺少将此位添加到web.config文件中的功能.终于解决了问题.

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

<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>


这篇关于IIS上的登录控制出了点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆