我有一个站点A,认证方式是集成Windows身份验证的。
现在我希望在另一个站点B提供一个链接,通过这个链接以某个固定的Windows账号登录到站点A。请问有什么方法达到?

解决方案 »

  1.   

    我想这个应该是不可行的吧,如果可行,那windows身份认证还有什么意义?
      

  2.   

    我觉得似乎不太可能吧如果这样的话,那WEB不是太脆弱了??
      

  3.   

    >>>通过这个链接以某个固定的Windows账号登录到站点Awhere does the link point to? 站点B?通过站点B的链接以某个固定的Windows账号登录到站点A?the traffice to 站点A is through this page on 站点B?
      

  4.   

    呵呵,打个比方,在域外的登录NT验证的A站点,需要输入用户名和密码,我希望在另外的B站点(匿名可登录)的C页面,提供一个链接(链至A站点),点击C页面的这个链接,不需要输入验证的NT帐户密码,实际上就是在C页面的后台代码中处理掉了。
       实现应该是可能的,比方说Sharepoint本来也是集成AD的,但她提供Single Sign-On的技术,可以提供账号映射的方式让外网的用户登录Portal。
       希望各位能够提供一些思路!!谢谢
      

  5.   

    在saucer大哥的blog上和csdn中找到些文章,不知道能否解决我的问题?^_^
    研究ing……
      

  6.   

    2个不同站之间的Single Sign-On不会这么简单的一般来说,一个站只认识来自它本站的认证cookie,要么直接认证种下认证cookie,要么转向一认证网站后确认账号后,再种下认证cookie
      

  7.   

    我只能提醒一点,用webService,登陆全部封装好服务,直接调用接口。
      

  8.   

    呵呵,楼上的解决不了问题,web service可以不通过NT验证访问数据,但是不能打开页面~~
      

  9.   

    How to authenticate against the Active Directory by using Forms authentication and Visual C# .NET
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q316748
    不知道这个咋的,看看ing……
      

  10.   

    [DllImport("advapi32.dll", SetLastError=true)]
    public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, 
    int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
    [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
    public extern static bool CloseHandle(IntPtr handle); [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
    public extern static bool DuplicateToken(IntPtr ExistingTokenHandle, 
    int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle); [DllImport("Kernel32.dll")]
    public static extern int GetLastError(); [PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
    private void LogON()
    {
    IntPtr tokenHandle = new IntPtr(0);
    IntPtr dupeTokenHandle = new IntPtr(0);
    try
    {
    string UserName, MachineName ,PassWord; // Get the user token for the specified user, machine, and password using the 
    // unmanaged LogonUser method.
    MachineName = this.txtMachinename.Text;
    UserName = this.txtUserName.Text;
    PassWord = this.txtpass.Text;
                
    // const int LOGON32_PROVIDER_WINNT50 = 2;
    // //This parameter causes LogonUser to create a primary token.
    // const int LOGON32_LOGON_INTERACTIVE = 3;
    const int SecurityImpersonation = 2; tokenHandle = IntPtr.Zero;
    dupeTokenHandle = IntPtr.Zero; // Call LogonUser to obtain a handle to an access token.
    bool returnValue = LogonUser(UserName, MachineName, PassWord, 
    Convert.ToInt32(this.txtdwLogonType.Text),Convert.ToInt32(this.txtdwLogonProvider.Text)
    ,ref tokenHandle);
                        
    this.TextBox1.Text = returnValue.ToString() +"    "+ GetLastError().ToString();

    // Check the identity.
    bool retVal = DuplicateToken(tokenHandle, SecurityImpersonation, ref dupeTokenHandle);
    if (false == retVal)

    return;
    }
    else
    {
    this.TextBox1.Text = "OK";
    }
    // The token that is passed to the following constructor must 
    // be a primary token in order to use it for impersonation.
    WindowsIdentity newId = new WindowsIdentity(dupeTokenHandle);
    WindowsImpersonationContext impersonatedUser = newId.Impersonate();
    // Check the identity.

    // Stop impersonating the user.
    impersonatedUser.Undo(); // Check the identity.
    // Free the tokens.
    if (tokenHandle != IntPtr.Zero)
    CloseHandle(tokenHandle);
    if (dupeTokenHandle != IntPtr.Zero) 
    CloseHandle(dupeTokenHandle);
    }
    catch(Exception ex)
    {
    this.TextBox1.Text = ex.Message;
    }
    }
      

  11.   

    楼上的楼上估计只能在同一个站点内模拟别的Windows账号
      

  12.   

    楼主的做法让我感觉很是蹩脚啊,呵呵
    ----------------------------------------呵呵,也有这种需求啊,例如你在外网给客户提供Demo,不希望将机器上的账号透露出去,看能否提供一个临时页面,在内部将Windows帐户封装起来,直接导航到需要的页面啊
      

  13.   

    一个ASP.NET 程序只能有一个进程用户,默认的为ASPNET用户,如果webconfig中设置为<identity impersonate="true"  /> 则用户时IUSER_计算机名,如果<identity impersonate="true"  userName="Domain\A" password="1"/> 则用户时domain域中的A用户,但这个用户权限一定要够。你也可以在程序中更改登陆用户,例如用
    [DllImport("advapi32.dll", SetLastError=true)]
    public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);API函数来得到用户认证,然后用
    WindowsIdentity newId = new WindowsIdentity(phToken);
    WindowsImpersonationContext impersonatedUser = newId.Impersonate();来模拟认证,更改登陆用户。
      

  14.   

    楼上的可以从模拟认证的站点登录到别的需要NT认证的站点吗??我试过是不可以的,如果有哪位成功过请将详细代码贴上来。^_^   我现在详细描述一下,在我的IIS中Default Site上,有两个Web Application,例如A和B,他们访问的页面就是Http://machinename/A/default.aspx和Http://machinename/B/default.aspx,A需要集成的windows身份验证,B则可以匿名登录。
       如果别人登录我的A应用,则会弹出一个要求输入账号密码的对话框。我希望别人先登录B应用,B应用用一个固定的Windows账号模拟登录到A的页面,这样就不会弹出对话框了。
      

  15.   

    ASP.NET 必须需要匿名登录,如果没有则会跳出帐号密码框,先通过IIS认证,才能进入ASP.NET的认证,我们讨论的身份验证都是ASP.NET的。
    具体认证过程可参考MSDN帮助上的:ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconaspnetdataflow.htm
      

  16.   

    look intoSingle Sign-On http://www.eggheadcafe.com/articles/20040317.asp
      

  17.   

    看到这个问题就很容易让人想去参考Sharepoint和SSO。如果不是从B站点链接到A站点,而是从B站点下面的一个虚拟目录影射到A站点,而且影射过程相当于自动登录,可以吗?例如http://SiteB/SiteA/Default.aspx就等于https://guest:guest@SiteA/Default.aspx(当然guest:guest只是举例说明有登录帐号,现在的IE都不允许这样传递帐号信息了)。如果可以的话,不如你就在SiteB建立一个站点/SiteA,然后放一个HttpHandler,作用就和代理一样把所有的Request加上用户验证信息然后pass给SiteA。