【问题标题】:How to pass user authentication when visiting another url?访问另一个网址时如何通过用户身份验证?
【发布时间】:2010-07-22 19:57:28
【问题描述】:

假设我有一个网络应用程序 MyApp。当我访问这个网络应用程序时,我已经输入了用户身份验证信息(用户名和密码),然后从这个站点,想要访问另一个站点说 YourSite,它也会要求身份验证。对于两个站点,相同的身份验证应该没问题。

所以我想在代码中将 MyApp 上的用户身份验证数据传递给 YourSite。然后我编写了一个 http 处理程序,例如:

public void ProcessRequest(HttpContext context)
{
   string url = "http://YourSite/page/...";            
   HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
   CredentialCache myCache = new CredentialCache();                        
   NetworkCredential netCredential = new NetworkCredential("myname", "mypassword", "");

   myCache.Add(new Uri(url), "Basic", netCredential);
   myCache.Add(new Uri(url), "Digest", netCredential);
   myCache.Add(new Uri(url), "Negotiate", netCredential);
   myReq.Credentials = myCache;
            //.....
}

但我不想在代码中设置用户名和密码,我想将当前用户身份验证数据传递给 YourSite。

如何实现这个请求?

==========关于我的情况的Moro信息: MyApp 是在 IIS(Windows 身份验证)上运行的 Asp.NET wep 应用程序。 YourSite 是一个 Java 应用程序,在另一个盒子上的 Tomcat 上运行。 两个应用程序都配置为使用同一 Windows 域服务器上的 Windows Active Directory 用户帐户。

============更多信息: 我将上面的代码更改为(尝试使用当前凭据):

 public void ProcessRequest(HttpContext context)
    {
       string url = "http://YourSite/page/...";            
       HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
       myReq.Credentials = CredentialCache.DefaultCredentials;

       //.....
    }

但无法通过身份验证。

【问题讨论】:

  • 您在应用程序上使用哪种身份验证来对用户进行身份验证(NTLM、Forms、Kerberos、Basic、Digest、OpenID、Passport、Google Auth 等)?远程站点呢?
  • 我在 MyApp 中使用 Windows 身份验证(NTLM)。在 IIS for MyApp 上,也配置为 Windows Authenticaton。

标签: asp.net authentication httphandler


【解决方案1】:

您能否在 YourSite 页面上使用 MyApp 网站的 1 像素 x 1 像素 iframe,然后通过 javascript/ajax 传递信息?我想我会同意 Darin 的评论并建议使用 OpenID,但这可能是一种选择。我还没有尝试过,所以如果它有效,请告诉我:)

【讨论】:

  • 谢谢。但是我没有机会在第三方产品 YourSite 上放任何东西。
【解决方案2】:

如果您的应用程序在同一个顶级域(myapp.abc.com 和 yourapp.abc.com)上运行,则只需在应用程序 web.config 中设置即可使用表单身份验证和成员资格提供程序:

Asp.net forms authentication and multiple domains

Scott Gu's Blog

如果域不同,您可以使用 SSO(单点登录)解决方案,例如: http://singlesignon.codeplex.com/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 2019-12-06
    • 1970-01-01
    相关资源
    最近更新 更多