Post Reply 
 
Thread Rating:
  • 1 Votes - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login System (ASP.NET C#)
06-05-2010, 04:49 PM
Post: #1
Login System (ASP.NET C#)
i have been trying to create a login system for a small project. The username and password are stored in MS SQL i can log in but the session will remain as not logged in any ideas why guys ?

protected void BtnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
SqlCommand command = new SqlCommand("SELECT * FROM Member WHERE MemberUsername = @Username AND MemberPassword = @Password", c.connection);
c.connection.Open();
command.Parameters.AddWithValue("@Username", TxtUsername.Text);
command.Parameters.AddWithValue("@Password", TxtPassword.Text);
SqlDataReader DataReader = command.ExecuteReader();

while (DataReader.Read())
{
if (DataReader["MemberRoleID"].ToString() == "1")
{
Session["userid"] = TxtUsername.Text;
LblWelcome.Text = "Welcome: " + (Session["userid"]);
Response.Redirect("Register.aspx");
BtnSubmit.Enabled = false;
}
else if (DataReader["MemberRoleID"].ToString() == "2")
{
Session["userid"] = TxtUsername.Text;
LblWelcome.Text = "Welcome: " + (Session["userid"]);
Response.Redirect("PostComments.aspx");
BtnSubmit.Enabled = false;
}
}
c.connection.Close();
}
}

Web Design
Web Design Melbourne | SEO Company
Find all posts by this user
Quote this message in a reply
08-12-2011, 08:33 PM
Post: #2
RE: Login System (ASP.NET C#)
Your codes look like in ASP.NET 2.0.

Firstly, please put your pages which need be secured into a folder "secured"(any names are available). And just login.aspx is staying at root path(out side of folder "secured").

Thus you can configure the web.config:

<system.web>

<roleManager enabled="true" />

<authentication mode="Forms">
<forms name=".ASPXUSERDEMO" loginUrl="login.aspx" protection="All" timeout="60"/> According to the roleManager configuration as below, any anonymous users will turn back to login.aspx

Pakistan's Local Search Engine | Yellow Pages of Pakistan
Find all posts by this user
Quote this message in a reply
08-13-2011, 07:29 PM
Post: #3
RE: Login System (ASP.NET C#)
This is just a small demonstration to show how easy one can "port" the code from my previous tutorials ( Updated: Simple ASP.Net Login Page & ASP.Net Login Page with SQL & ASP.Net Registration Page) over to another programming language in the .NET environment. In this example I chose to use C#.

So for all considerations this tutorial is an exact duplicate of the Updated: Simple ASP.NET Login Page using VB.NET that I did previously, but using SQL instead of Access for the DB



1. Create a Login Webform (HTML/ASP.NET)
- Include any control validation you feel necessary.

Hair Transplant
Find all posts by this user
Quote this message in a reply
01-18-2012, 08:08 PM
Post: #4
RE: Login System (ASP.NET C#)
here's the link with a detailed video tutorial. its very easy. and you can even download the code. hope this helps........give it a try

http://www.asp.net/learn/videos/video-47.aspx

Thanks

Hair Transplant Pakistan
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)