Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.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
C# 在c网页中自动登录不起作用_C#_Active Directory - Fatal编程技术网

C# 在c网页中自动登录不起作用

C# 在c网页中自动登录不起作用,c#,active-directory,C#,Active Directory,我的网页有一种奇怪的行为。 我已自动登录,获取Active directory用户名。 这在我的笔记本电脑上运行得非常好。我将网络移动到了我笔记本电脑上的iis服务器 问题是: 当另一个用户在另一台笔记本电脑上打开网页时,同一网络会出现一个自动弹出窗口,询问用户名和密码 我怎样才能避免呢 希望你的帮助 我的索引代码: public partial class index : System.Web.UI.Page { string usuario_ldap, rut_empleado,

我的网页有一种奇怪的行为。 我已自动登录,获取Active directory用户名。 这在我的笔记本电脑上运行得非常好。我将网络移动到了我笔记本电脑上的iis服务器

问题是: 当另一个用户在另一台笔记本电脑上打开网页时,同一网络会出现一个自动弹出窗口,询问用户名和密码

我怎样才能避免呢

希望你的帮助

我的索引代码:

 public partial class index : System.Web.UI.Page
{
    string usuario_ldap, rut_empleado, username;
    UserPrincipal usuario_data;
    protected void Page_Load(object sender, EventArgs e)
    {


   username = HttpContext.Current.User.Identity.Name;
    string[] usuario = username.Split('\\');
        usuario_data = GetActiveDirectoryUser(usuario[1]);
        usuario_ldap = usuario_data.DisplayName;
        rut_empleado =  usuario_data.EmployeeId;

         if (isAdmin(rut_empleado) == true)
             {

                Session["administrador"] = true;              
             }
         else
              {
                Session["administrador"] = null;

              }

              Session["logon"] = usuario_ldap;

         if (Session["logon"] == null)
             {          
                 Response.Redirect(" login.aspx? name=" + Session["logon"]);

              }
         else
              {
              Response.Redirect("INGRESO.aspx");
             } 
    }



   public bool isAdmin(string rut)
     {

         string cs = ConfigurationManager.ConnectionStrings["conexionsql"].ConnectionString;
         SqlConnection con = new SqlConnection(cs);
                    try
                    {
                        con.Open();

                    }
                    catch (SqlException e)
                    {

                    }


  SqlCommand command = new SqlCommand("select * from IngT_Administrador where rut = @rut", con);
                    command.Parameters.AddWithValue("@rut", rut.Trim());

                   SqlDataReader reader = command.ExecuteReader();
                   if (reader.Read())
                    {
                        con.Close();
                        return true;
                    }
                    else
                    {
                        con.Close();
                        return false;
                    } 

                }

    private UserPrincipal GetActiveDirectoryUser(string userName)
    {
        using (var ctx = new PrincipalContext(ContextType.Domain))
        using (var user = new UserPrincipal(ctx) { SamAccountName = userName })
        using (var searcher = new PrincipalSearcher(user))
        {
            return searcher.FindOne() as UserPrincipal;
        }
    }
我的网络配置是:

 <?xml version="1.0" encoding="UTF-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>


    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="*" />
      </assemblies>
    </compilation>

    <authorization>
      <deny users="?" />
    </authorization>


  </system.web>

  <connectionStrings> 
    <clear />
    <remove name="LocalSqlServer" />
   <add connectionString="data source=.\SQLEXPRESS;Integrated     Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" name="LocalSqlServer"/>

<add connectionString="Server=10.10.201.79;Database=DesaInterno;User ID=usuario_de_conexion;Password=a" name="conexionsql" />
</connectionStrings>

</configuration>

您是网络用户帐户的管理员吗?另一个笔记本电脑用户是管理员吗?你使用的浏览器相同吗?在某些情况下,比如LDAP,Chrome的行为与IE不同。我们使用Chrome进行测试。在我的笔记本电脑中,当我运行该网页时,它会显示以下url://localhost:81/FORMULARIO_INGRESO/INGRESO.aspx------------------其他用户必须使用url ip运行//privateip:81/FORMULARIO_Ingreo/Ingreo.aspxYou仅查看用户是否尝试使用Active Directory中存在的用户名登录,而完全不是健壮/安全的。。。看看@funkeeiads,尝试使用ip登录你的笔记本电脑//隐私:81/FORMULARIO_Ingreo/Ingreo.aspx