Click here to Skip to main content
16,013,207 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Changing property through javascript Pin
RaviJJain23-Nov-06 20:56
RaviJJain23-Nov-06 20:56 
QuestionHelp [modified] Pin
Imran Khan Pathan23-Nov-06 0:46
Imran Khan Pathan23-Nov-06 0:46 
Question"datagrid paging" Pin
ravikiranreddydharmannagari22-Nov-06 23:48
ravikiranreddydharmannagari22-Nov-06 23:48 
AnswerRe: "datagrid paging" Pin
_mubashir23-Nov-06 0:12
_mubashir23-Nov-06 0:12 
QuestionHelp !!! Pin
sukhchain singh22-Nov-06 23:40
sukhchain singh22-Nov-06 23:40 
AnswerDouble post Pin
leckey25-Nov-06 15:41
leckey25-Nov-06 15:41 
QuestionSetting username/passwords in the web.config using forms authentication? Pin
Red_Wizard_Shot_The_Food22-Nov-06 23:34
Red_Wizard_Shot_The_Food22-Nov-06 23:34 
AnswerRe: Setting username/passwords in the web.config using forms authentication? Pin
Britney S. Morales23-Nov-06 8:21
Britney S. Morales23-Nov-06 8:21 
This is from asp.net technical articles site

Listing 8. Denying anonymous users access
<authorization>
<deny users=? />
</authorization>

We could also have added <deny> elements for specific user names, allowed access to some users and not others, and so on.
User names and passwords
For our purposes, the easiest way to store user names and passwords is in the Web.config XML file, right alongside the other authentication information. In reality, because user names and passwords are accessed programmatically in ASP.NET (as we will see shortly), you could easily retrieve them from a database or a customized XML file of your own design. In many cases such methods will be preferable (and possibly more similar to what you did with your JSP applications), so we will point out where and when such code should be added when we look at the ASP.NET code in just a moment.
For now, find the <authentication> element in Web.config again and add to it so that it looks like Listing 9.

Listing 9. Storing user name and password information in Web.config
<authentication mode="Forms">
<forms name="LoginForm" loginUrl="login.aspx" protection="All" />
<credentials passwordFormat="Clear">
<user name="craig" password="secret"/>
</credentials>
</forms>
</authentication>

Using the <credentials> element, we have added one user to the list of potential users for this application. We will see in a moment how to check against the users in this list. For now, note the passwordFormat attribute; a value of Clear indicates that this password will be readable to humans (that is, unencoded). Additional values are available that will cause the password to be encrypted before being sent across the network.
Designing a login form
Unlike in our JSP example, we can take advantage of Visual Studio .NET and design the appearance of our ASP.NET login form using the forms designer, and place all important code in the CodeBehind file. This allows us to have a much better idea of what the form will look like while designing it, and also allows us to keep most of the C# code separate from the HTML page design.
We'll start by adding a new form to the project called Login.aspx. We can add some text fields and a button to this form to make it look similar to the form we created in our JSP example simply drag and drop the necessary components into the design window and arrange them.
Now, open the CodeBehind file for Login.aspx. Here we need to add code in two different places. First, we need to add the following using directive to the top of the page:
using System.Web.Security;

This namespace contains all the necessary classes for ASP.NET security.
We then need to add some code to verify the user name and password to the Click method corresponding to our login button. If your CodeBehind does not already contain a Button1_Click method, go back to the form editor and double-click the login button to create one. Inside Button1_Click, add code as shown in Listing 10.

Listing 10. Button1_Click code for forms-based authentication
private void Button1_Click(object sender, System.EventArgs e) {
if (FormsAuthentication.Authenticate(TextBox1.Text, TextBox2.Text)) {
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
} else {
Label1.Text = "Login failed. Please try again.";
}
}

Big Grin | :-D



keep Learning and you never will be out of date...
QuestionSend mail Pin
aasstt22-Nov-06 22:19
aasstt22-Nov-06 22:19 
AnswerRe: Send mail Pin
Steven J Jowett22-Nov-06 23:36
Steven J Jowett22-Nov-06 23:36 
AnswerRe: Send mail Pin
Britney S. Morales23-Nov-06 3:46
Britney S. Morales23-Nov-06 3:46 
Questionsms system Pin
jabbarsb22-Nov-06 21:39
jabbarsb22-Nov-06 21:39 
AnswerRe: sms system Pin
Coding C#22-Nov-06 23:17
Coding C#22-Nov-06 23:17 
GeneralRe: sms system Pin
jabbarsb22-Nov-06 23:31
jabbarsb22-Nov-06 23:31 
GeneralRe: sms system Pin
Coding C#23-Nov-06 19:07
Coding C#23-Nov-06 19:07 
QuestionDropdown Menu Pin
Rajiya22-Nov-06 20:13
Rajiya22-Nov-06 20:13 
AnswerRe: Dropdown Menu Pin
Imran Khan Pathan22-Nov-06 21:48
Imran Khan Pathan22-Nov-06 21:48 
GeneralRe: Dropdown Menu Pin
Rajiya23-Nov-06 0:32
Rajiya23-Nov-06 0:32 
Questionfind whether a datatable is present or not in a dataset Pin
pavansagar122-Nov-06 20:10
pavansagar122-Nov-06 20:10 
AnswerRe: find whether a datatable is present or not in a dataset Pin
Tamimi - Code22-Nov-06 20:33
Tamimi - Code22-Nov-06 20:33 
QuestionDropdownlist problem as DataGrid Control Pin
param thaker22-Nov-06 20:07
param thaker22-Nov-06 20:07 
AnswerRe: Dropdownlist problem as DataGrid Control Pin
_AK_22-Nov-06 21:02
_AK_22-Nov-06 21:02 
QuestionHow to use google earth from my web application? Pin
Guru_yogi22-Nov-06 19:41
Guru_yogi22-Nov-06 19:41 
Questionfile copyi from one machine to another in asp.net Pin
Guru_yogi22-Nov-06 19:36
Guru_yogi22-Nov-06 19:36 
Question"placing image on webform" Pin
ravikiranreddydharmannagari22-Nov-06 19:21
ravikiranreddydharmannagari22-Nov-06 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.