2011-04-12 42 views
1

作为标题说明如何允许用户使用他们在注册时指定的电子邮件登录。如何允许使用asp注册组件通过电子邮件登录

使用asp 3.5,登录和注册都是内置的visual studio。

也有一种方法来删除秘密的问题和答案。

感谢

+0

“还有一种方法可以删除最喜欢的问题和答案。”什么? – Earlz 2011-04-13 00:16:34

+0

抱歉,事情混淆了。我的意思是秘密 – Wahtever 2011-04-13 09:23:53

回答

0

我的简单而有效的这种解决方法是做到以下几点:

1-重命名的标签用户名字段电子邮件:(这样用户会看到它通过电子邮件,但它实际上是仍然是ASP.NET成员资格将保存的用户名)。

2-通常保存我的入口沿侧与任何额外的信息,我需要保存

3-现在我的用户将被强制使用他们提供的电子邮件登录

4-笑脸:)

+0

谢谢你,一个简单而简单的方法 – Wahtever 2011-04-13 20:14:35

0

我认为你正在寻找窗体身份验证。谷歌有很多说明。或在这里看到:http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.aspx

你需要控制的登录点击事件连接到您的验证逻辑,

protected void Login_Click(object sender, EventArgs e) 
    { 
     // your logic here 
    } 

而且像下面应该进入Global.asax.cs中创建一个身份验证票证( cookie)代表用户认证的会话。

protected void Application_AuthenticateRequest(object sender, EventArgs e) 
    { 
     String cookieName = FormsAuthentication.FormsCookieName; 
     HttpCookie authCookie = Context.Request.Cookies[cookieName]; 

     if (null == authCookie) 
     {//There is no authentication cookie. 
      return; 
     } 

     FormsAuthenticationTicket authTicket = null; 

     try 
     { 
      authTicket = FormsAuthentication.Decrypt(authCookie.Value); 
     } 
     catch (Exception ex) 
     { 
      //Write the exception to the Event Log. 
      return; 
     } 

     if (null == authTicket) 
     {//Cookie failed to decrypt. 
      return; 
     } 

     //When the ticket was created, the UserData property was assigned a 
     //pipe-delimited string of group names. 
     String[] groups = authTicket.UserData.Split(new char[] { '|' }); 

     //Create an Identity. 
     GenericIdentity id = new GenericIdentity(authTicket.Name, "LdapAuthentication"); 

     //This principal flows throughout the request. 
     GenericPrincipal principal = new GenericPrincipal(id, groups); 

     Context.User = principal; 
    } 

您还需要一个'IsAuthenticted'布尔方法来包含验证的逻辑。在你的情况下,你需要将他们的电子邮件地址存储在某个地方,并将认证逻辑指向该源。

相关问题