Facebook和放大器;谷歌登录asp.net网站 [英] Facebook & Google Login for asp.net website
问题描述
有关我的asp.net网站,我是想FB和放放功能;谷歌登录。我发现从 ASPSNIPPETS 教程。现在,在此我所做的是,如果在Facebook上登录按钮的用户点击它然后第一个授权用户放大器;获得小组用户详细信息。然后,我把我的code,检查用户是否已经存在于我的分贝与否。如果没有,那么它插入用户的放大器;然后把登录code。我的问题是执行$ C $的第一线c其停止进一步执行,使其无法检查用户是否登录或不与功放后;等等。我想这可能是因为重定向URL阻止其进一步codeSØ执行的。我怎样才能解决这个问题?
保护小组登录(发送者为对象,E作为EventArgs的)
FaceBookConnect.Authorize(user_photos,电子邮件,Request.Url.AbsoluteUri.Split(?C)(0))如果不String.IsNullOrEmpty(lblId.Text)然后
昏暗的查询作为字符串=选择ID,邮箱用户的ID在哪里@ = ID
con.Open()
DIM CMD作为新的MySqlCommand(查询,CON)
cmd.Parameters.AddWithValue(@ ID,lblId.Text)
昏暗的博士担任了MySqlDataReader = cmd.ExecuteReader()
如果dr.HasRows然后
不要登录code在这里
尝试
昏暗str作为字符串=从用户选择*其中ID ='+ lblId.Text +;
昏暗CMD2作为新的MySqlCommand(STR,CON)
昏暗的DA作为新MySqlDataAdapter的(CMD2)
Response.Cookies(USER_TYPE)。值=用户
Response.Cookies(chkusername)。值= lblId.Text
的Response.Redirect(Request.Url.AbsoluteUri)
welcome.Visible = TRUE
抓住EX为例外
的Response.Write(前)
结束Try
其他
尝试
昏暗STR1的String =INSERT INTO用户(ID,DP,显示名)VALUES('+ lblId.Text +,+ ProfileImage.ImageUrl.ToString +,+ lblName.Text +')
昏暗的适配器作为新MySqlDataAdapter的
昏暗的命令作为新的MySqlCommand
dr.Close()
command.CommandText = STR1
command.Connection = CON
adapter.SelectCommand =命令
command.ExecuteNonQuery()
抓住EX为例外
的Response.Write(前)
结束Try
昏暗CON2作为新的MySqlConnection(的ConnectionString)
con2.Open()
昏暗CMD3作为新的MySqlCommand(选择ID,邮箱用户的ID在哪里@ = ID,CON2)
cmd3.Parameters.AddWithValue(@ ID,lblId.Text)
昏暗DR2作为了MySqlDataReader = cmd3.ExecuteReader()
如果dr2.HasRows然后
不要登录code在这里
尝试
昏暗str作为字符串=从用户选择*其中ID ='+ lblId.Text +;
昏暗CMD2作为新的MySqlCommand(STR,CON2)
con2.Open()
昏暗的DA作为新MySqlDataAdapter的(CMD3)
Response.Cookies(USER_TYPE)。值=用户
Response.Cookies(chkusername)。值= lblId.Text
的Response.Redirect(Request.Url.AbsoluteUri)
抓住EX为例外
的Response.Write(前)
con2.Close()
结束Try
con.Close()
万一 万一
万一
con.Close()
结束小组
首先,你可以优化你的code:
如果不String.IsNullOrEmpty(lblId.Text)然后
昏暗str作为字符串=从用户选择*其中ID = @ ID
con.Open()
昏暗CMD2作为新的MySqlCommand(STR,CON)
cmd.Parameters.AddWithValue(@ ID,lblId.Text)
昏暗的DA作为新Common.DataAdapter(CMD2)
昏暗的DS作为新Data.DataSet()
da.Fill(DS)
如果ds.Tables(0).Rows.Count> 0,则
不要登录code在这里
尝试 Response.Cookies(USER_TYPE)。值=用户
Response.Cookies(chkusername)。值= lblId.Text
的Response.Redirect(Request.Url.AbsoluteUri)
welcome.Visible = TRUE
抓住EX为例外
的Response.Write(前)
结束Try
其他
尝试
昏暗STR1的String =INSERT INTO用户(ID,DP,显示名)的值(@id,@ IMG,@名)
DIM CMD作为新的MySqlCommand
CMD =新的SqlCommand(REQ,CON)
cmd.Parameters.Add(新的SqlParameter(@ ID,lblId.Text))
cmd.Parameters.Add(新的SqlParameter(@ IMG,ProfileImage.ImageUrl.ToString))
cmd.Parameters.Add(新的SqlParameter(@名,lblName.Text))
cmd.ExecuteNonQuery()
抓住EX为例外
的Response.Write(前)
结束Try
插入后,您不必从数据库中选择只发送参数饼干
Response.Cookies(USER_TYPE)。值=用户
Response.Cookies(chkusername)。值= lblId.Text
的Response.Redirect(Request.Url.AbsoluteUri) 万一
con.Close()
万一
For my asp.net website I was trying put feature of FB & Google Login. I found tutorial from ASPSNIPPETS. Now in this what I have done is If user click on Facebook Login button then It first authorize the user & get user details in panel. Then I put my code to check whether user already exist in my db or not. If not then it Inserts user & then put login code. My Problem is after executing first line of code it stops executing further so that It is unable to check whether user is logged in or not & so on. I think it may be because of redirect url which stops further codes o execute. How Can I eliminate this problem?
Protected Sub Login(sender As Object, e As EventArgs)
FaceBookConnect.Authorize("user_photos,email", Request.Url.AbsoluteUri.Split("?"c)(0))
If Not String.IsNullOrEmpty(lblId.Text) Then
Dim query As String = "Select ID, email From users where ID=@id"
con.Open()
Dim cmd As New MySqlCommand(query, con)
cmd.Parameters.AddWithValue("@id", lblId.Text)
Dim dr As MySqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
'Do Login Code here
Try
Dim str As String = "select * from users where ID='" + lblId.Text + "';"
Dim cmd2 As New MySqlCommand(str, con)
Dim da As New MySqlDataAdapter(cmd2)
Response.Cookies("User_Type").Value = "users"
Response.Cookies("chkusername").Value = lblId.Text
Response.Redirect(Request.Url.AbsoluteUri)
welcome.Visible = True
Catch ex As Exception
Response.Write(ex)
End Try
Else
Try
Dim str1 As String = "INSERT INTO users (ID, DP, displayName) values('" + lblId.Text + "', '" + ProfileImage.ImageUrl.ToString + "', '" + lblName.Text + "')"
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
dr.Close()
command.CommandText = str1
command.Connection = con
adapter.SelectCommand = command
command.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex)
End Try
Dim con2 As New MySqlConnection("connectionstring")
con2.Open()
Dim cmd3 As New MySqlCommand("Select ID, email From users where ID=@id", con2)
cmd3.Parameters.AddWithValue("@id", lblId.Text)
Dim dr2 As MySqlDataReader = cmd3.ExecuteReader()
If dr2.HasRows Then
'Do Login Code here
Try
Dim str As String = "select * from users where ID='" + lblId.Text + "';"
Dim cmd2 As New MySqlCommand(str, con2)
con2.Open()
Dim da As New MySqlDataAdapter(cmd3)
Response.Cookies("User_Type").Value = "users"
Response.Cookies("chkusername").Value = lblId.Text
Response.Redirect(Request.Url.AbsoluteUri)
Catch ex As Exception
Response.Write(ex)
con2.Close()
End Try
con.Close()
End If
End If
End If
con.Close()
End Sub
First you can optimise your code :
If Not String.IsNullOrEmpty(lblId.Text) Then
Dim str As String = "select * from users where ID=@id"
con.Open()
Dim cmd2 As New MySqlCommand(str, con)
cmd.Parameters.AddWithValue("@id", lblId.Text)
Dim da As New Common.DataAdapter(cmd2)
Dim ds As New Data.DataSet()
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
'Do Login Code here
Try
Response.Cookies("User_Type").Value = "users"
Response.Cookies("chkusername").Value = lblId.Text
Response.Redirect(Request.Url.AbsoluteUri)
welcome.Visible = True
Catch ex As Exception
Response.Write(ex)
End Try
Else
Try
Dim str1 As String = "INSERT INTO users (ID, DP, displayName) values(@id, @img,@name)"
Dim cmd As New MySqlCommand
cmd = New SqlCommand(req, con)
cmd.Parameters.Add(New SqlParameter("@id", lblId.Text))
cmd.Parameters.Add(New SqlParameter("@img", ProfileImage.ImageUrl.ToString))
cmd.Parameters.Add(New SqlParameter("@name", lblName.Text))
cmd.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex)
End Try
'After insertion you don't have to select from database just send the parameters to cookies
Response.Cookies("User_Type").Value = "users"
Response.Cookies("chkusername").Value = lblId.Text
Response.Redirect(Request.Url.AbsoluteUri)
End If
con.Close()
End If
这篇关于Facebook和放大器;谷歌登录asp.net网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!