用于验证ASP.net网站的Gmail凭证 [英] Gmail credentials for Authentication of ASP.net Website

查看:142
本文介绍了用于验证ASP.net网站的Gmail凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案



 < form id =form1runat =server> 
< div id =loginform>
< div id =NotLoggedInrunat =server>
使用< img src =http://www.google.com/favicon.ico/>登录
< asp:按钮ID =btnLoginToGoogleRunat =serverText =GoogleOnCommand =OpenLogin_Click
CommandArgument =https://www.google.com/accounts/o8/ id/>
< p />< asp:Label runat =serverID =lblAlertMsg/>
< / div>
< / div>
< / form>

使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用DotNetOpenAuth.OpenId;
使用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);
休息;
case AuthenticationStatus.Canceled:
lblAlertMsg.Text =取消。;
休息;




保护无效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();
}
}

但是我仍然有进一步的疑问是如何获得用户登录后创建会话的用户名... ???我可以看到它在某处...


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.

解决方案

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...

这篇关于用于验证ASP.net网站的Gmail凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆