Trying to get login to work

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I'd like to add a user login to my site, but my attempts have failed so far. What all do I need to do to make a login work? Does it automatically create the file to store the users? I thought I had added myself as a user with a password when I dropped the login control, but when I moved the page to my web server folder and loaded it, my login failed. After I get the login to work, I'd like it to go to a specific page after the user logs in. Thanks for any help.
 
Thanks. I read that information and configured everything like they said, but every time I try to log into my site, it says the login failed. The MDF file has my login info and I'm typing it correctly. I thought from the one video that you don't really have to put any code behind the login control, because it handles it for you. Is this correct? Why isn't my login working?
 
Forms-based Authentication in ASP.Net application

Hi,

Forms Authentication allows developers to store the authentication information, such as username and password, in the Web.config file. The user’s request will go to IIS first and the user is authenticated by IIS. If the anonymous access is enabled in IIS or the user is successfully authenticated, it will hand off the request to ASP.NET application. ASP.NET checks to see whether a valid authentication cookie is attached to the request. If it is, it means the user credentials has been previously authenticated. ASP.NET will then perform the authorization check. If the user is authorized to access those resources, the access will be granted. Otherwise, the “access-denied” message is sent.

If the request does not have any cookie attached, ASP.NET redirects the user to the login page and solicits the credentials then resubmits for authentication. The application code checks those credentials. If authenticated, ASP.NET will attach the authentication ticket in the form of cookie to the response. If failed, the user is redirected back to the login page telling the user that the username/password is invalid.

Setting up the Forms-based authentication involves 4 steps:

1. Enable anonymous access in IIS

This has to be done as most of the users are considered to be non-Windows users, so they can get through IIS to get to ASP.NET. ASP.NET will always allow anonymous access to the login page though.

2. Configure <authentication> section in Web.config file

Web.config file contains the information related to the level and type of authentication service that is provided for a web application. The Forms-based authentication is enabled for a web application
by setting the authentication mode attribute to Forms as shown below.

<authentication mode=”Forms”>
<forms>
Name=”.MyCookie”
loginUrl=”/login.aspx”
protection=”All”
timeout=”80"
path=”/”
</forms>
</authentication>

As shown in the code above, the Name attribute is the name of HTTP cookie. The attribute loginURL is set to Login.aspx, which is the web page that is used for authenticating user credentials. The requests are redirected to a particular URL in loginURL, if the user is not authenticated.
The cookie protection is set to All. This causes the ASP.NET runtime to not only encrypt the cookie contents, but also validate the cookie contents. The timeout is set to 80, which means in 80 minutes the authentication cookie will expire. The idea behind this is to reduce the chance someone stealing the form authentication cookie. By reducing this, the cookie will be regenerated more often. The path attribute refers to the path of cookie to be sent to the client. It is set to “/” which means the cookie path is the root directory. In the standard method of Forms Authentication, all user information is stored in the Web.config as shown below.

<authentication mode=”Forms”>
<forms>
Name=”.MyCookie”
loginUrl=”/login.aspx”
protection=”All”
timeout=”80"
path=”/”
<credentials passwordFormat=”Clear”>
<user name=”Sam” password=”Test”/>
<user name=”Ram” password=”Test”/>
</credentials>
</forms>
</authentication>


Creating a login page and write the code as shown below.

Sub Button_Click(ByVal s As Object, ByVal e As EventArgs)
If IsValid Then
If FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, False)
Else
lblMessage.Text = “Bad username/password!”
End If

End If
End Sub

Hope this helps.

Regards
bhar
Knowledge is power
http://www.vkinfotek.com
 
Here is a video (the second half of that video anyways) that shows how to use the Login Control and never write any code. All you do is set a few properties and all. It works like a champ. However; I am still having sort of the same problem that when I try to access the site through IIS it fails. It works when testing, fails when deploying, and for the sake of it I never moved any files or anything. I pointed the IIS Virtual Directory directly to my Website Project Folder. So, the Login Control works great but how do you deploy it is my question.
 
How you deploy it will depend on your dataStore type and hosting situation.
I have developed such an app where I used MS SQL Server Express to develop, then deployed to an MS SQL Server. To deploy, I scripted the database using SQL Server Management Studio Express and ran the script in myLittleAdmin on my host control panel. Then changed the connectionstring in the web.config file.
There is a new toolkit designed to help deploy SQL solutions called SQL Server Hosting Toolkit. And Scott Gu of Microsoft has a tutorial on his blog: Recipe: Deploying a SQL Database to a Remote Hosting Environment (Part 1)
 
All I have is SQL Server Express installed on my home server (the one I use to host the site as well). Is SQL Server Express only for developing applications? I was under the impression I could use it as long as I didn't go over the 4gig mark on it. I do understand though how this tool can help you deploy to another SQL Environment which is nice. My issue is just from the same machine, the same SQL it only works in design mode not through IIS.
 
Back
Top