用于 ASP.net 网站身份验证的 Gmail 凭据

发布于 2025-01-03 08:53:45 字数 170 浏览 1 评论 0原文

我有两个用户名和密码文本框,现在我希望用户输入他们的公司电子邮件 ID 和密码(用户名和密码由 google 提供支持,网络服务器是 google)并登录到 ASP.net 网站。创建用户名和密码会话。此外,我希望用户能够使用相同的 gmail 凭据从 asp.net 网站发送电子邮件。提前感谢您,任何类型的帮助将不胜感激。

I have two textboxes for username and password now i want users to enter their company email Id and password (Username and password is powered by google ,webserver is google) and log in to the ASP.net website.Create session of username and password .Futher i want the user to able to send the email from asp.net website using same gmail credential.Thank you in advance and any type of help will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惟欲睡 2025-01-10 08:53:45

您应该检查 C# 的 OpenId 库。

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

这将为您提供良好的体验开始。这样,用户就不必直接使用其密码,并将被重定向到为您的网站授予身份验证的提供商。

You should check the OpenId library for C#.

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

This will give you a good start. This way, the user won't have to use his password directly and will be redirect to the provider that will grant authentification for your site.

萌酱 2025-01-10 08:53:45

我想要的答案是这个,这个代码工作正常。而且我没有在会话和数据库中的任何地方存储密码。

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

但我仍然进一步怀疑如何获取用户登录以创建会话的用户名...???可以完成我在某处看到过它...

Answer which i wanted is this and this code works fine.and I am not storing password anywhere in the session and database.

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

but i still have further doubt is how to get the username by which the user is logged to create session ...???It can be done i have seen it somewhere...

自此以后,行同陌路 2025-01-10 08:53:45

不,谷歌不会让你这样做。您必须执行类似于 StackOverflow 正在执行的操作(提供 OpenID 功能来在 google.com 上进行身份验证)。

Nah, Google won't let you do that. You'll have to do something similar to what StackOverflow is doing (provide OpenID functionality to authenticate at google.com).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文