![]() |
Login System (ASP.NET C#) - Printable Version +- Web Design Forum HTML CSS JavaScript PHP Graphic Design SEO forum (http://www.webdesignforum.com.au) +-- Forum: Web and Graphic Design (/forumdisplay.php?fid=1) +--- Forum: Programming (/forumdisplay.php?fid=10) +--- Thread: Login System (ASP.NET C#) (/showthread.php?tid=29) |
Login System (ASP.NET C#) - dreamcon - 06-05-2010 04:49 PM 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(); } } RE: Login System (ASP.NET C#) - dianna - 08-12-2011 08:33 PM 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 RE: Login System (ASP.NET C#) - netshet - 08-13-2011 07:29 PM 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. RE: Login System (ASP.NET C#) - hairtransplant - 01-18-2012 08:08 PM 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 |