簡體   English   中英

用於ASP.net網站身份驗證的Gmail憑據

[英]Gmail credentials for Authentication of ASP.net Website

我有兩個用於輸入用戶名和密碼的文本框,現在我希望用戶輸入其公司電子郵件ID和密碼(用戶名和密碼由google提供動力,網絡服務器是google)並登錄到ASP.net網站。創建用戶名和密碼會話。此外,我希望用戶能夠使用相同的gmail憑據從asp.net網站發送電子郵件。在此先感謝您,我們將不勝感激。

您應該檢查C#的OpenId庫。

http://code.google.com/p/dotnetopenid/

這將為您提供一個良好的開端。 這樣,用戶將不必直接使用其密碼,而將被重定向到將為您的站點授予身份驗證的提供程序。

我想要的答案是這個,此代碼可以正常工作。我沒有在會話和數據庫中的任何地方存儲密碼。

<form id="form1" runat="server">  
      <div id="loginform">  
        <div id="NotLoggedIn" runat="server">  
          Log in with <img src="http://www.google.com/favicon.ico" />  
            <asp:Button ID="btnLoginToGoogle" Runat="server" Text="Google"     OnCommand="OpenLogin_Click"  
              CommandArgument="https://www.google.com/accounts/o8/id" />  
          <p /><asp:Label runat="server" ID="lblAlertMsg" />  
        </div>  
      </div>  
    </form>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OpenIdAjaxRelyingParty rp = new OpenIdAjaxRelyingParty();
        var r = rp.GetResponse();
        if (r != null)
        {
            switch (r.Status)
            {


       case AuthenticationStatus.Authenticated:
                NotLoggedIn.Visible = false;
                Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString();
                Response.Redirect("Default2.aspx");
                break;
            case AuthenticationStatus.Canceled:
                lblAlertMsg.Text = "Cancelled.";
                break;
        }

    }

}
protected void OpenLogin_Click(object sender, CommandEventArgs e)
{
    string discoveryUri = e.CommandArgument.ToString();
    OpenIdRelyingParty openid = new OpenIdRelyingParty();
    var b = new UriBuilder(Request.Url) { Query = "" };
    var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
    req.RedirectToProvider();
}
}

但我還有一個疑問:如何獲取登錄用戶以創建會話的用戶名... ???可以完成,我已經在某處看到了...

不,Google不會允許您這樣做。 您必須執行與StackOverflow相似的操作(提供OpenID功能以 google.com上進行身份驗證)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM