Monday 1 April 2013

Signup/sign in for Social networking website


Signup/sign in for Social networking website


Here goes Opensource  social networking application  signup sign in feature.Application is developed in ASP.NET 3.0 framework along with Microsoft enterprise library for database connectivity.A good start for those who are planning to develop a social networking website like FACEBOOK.The application has examples of how to do session handling in ASP.NET,Database connectivity, Interaction of content page with the master page,Roles and Rights management.
Session handling example code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if (Session["username"] == null)
        {
            Response.Redirect("login.aspx");
 
        }
 
        else
        {
            Label messageLabel2 = (Label)Master.FindControl("username");
 
            messageLabel2.Text = Session["username"].ToString();
 
            string username = Session["username"].ToString();
 
            BusinessLayerClass SecurityBO = new BusinessLayerClass();
 
            DataSet userrole = SecurityBO.GetUserRole(username);
 
            if (userrole.Tables[0].Rows.Count > 0)
            {
 
                if (userrole.Tables[0].Rows[0]["RoleName"].Equals("Administrator"))
                {
                    LabelAdmin.Visible = true;
                    LabelNormalUser.Visible = false;
                    adminpage.Visible = true;
 
                }
 
                else
                {
                    LabelAdmin.Visible = false;
                    LabelNormalUser.Visible = true;
                    adminpage.Visible = false;
 
                }
 
            }
Interaction of content page with master page
?
1
2
3
Label messageLabel2 = (Label)Master.FindControl("username");
 
 messageLabel2.Text = Session["username"].ToString();
Roles and Rights management code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
BusinessLayerClass SecurityBO = new BusinessLayerClass();
 
           DataSet userrole = SecurityBO.GetUserRole(username);
 
           if (userrole.Tables[0].Rows.Count > 0)
           {
 
               if (userrole.Tables[0].Rows[0]["RoleName"].Equals("Administrator"))
               {
                   LabelAdmin.Visible = true;
                   LabelNormalUser.Visible = false;
                   adminpage.Visible = true;
 
               }
 
               else
               {
                   LabelAdmin.Visible = false;
                   LabelNormalUser.Visible = true;
                   adminpage.Visible = false;
 
               }
 
           }
Database connectivity example
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
public class DAOBase
   {
       private string _CurrentConnectionString = "connection";
       internal Database Database;
 
       public DAOBase()
       {
 
           Database = DatabaseFactory.CreateDatabase(this.CurrentConnectionString);
 
       }
 
       public string CurrentConnectionString
       {
           get
           {
               return this._CurrentConnectionString;
           }
       }
 
       public DbTransaction BeginTransaction()
       {
           DbTransaction transaction;
 
           IDbConnection connection = Database.CreateConnection();
 
           connection.Open();
 
           transaction = (DbTransaction) connection.BeginTransaction();
 
           return transaction;
       }
 
       public bool EndTransaction(DbTransaction transaction)
       {
           if (transaction != null)
           {
               DbConnection connection = transaction.Connection;
 
               if (connection != null)
               {
                   transaction.Dispose();
                   connection.Close();
 
                   return true;
               }
           }
 
           return false;
       }
   }
Source Code  includes  (Project solution in visual studio 2o10. Database script file for Microsoft SQL Server 2005/2008
Click here to download the complete project source code

No comments:

Post a Comment