Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

about authentication mode in asp.net

0.00/5 (No votes)
7 Jun 2006 1  
When you begin a asp.net programe,you can consider authentication that's value either 'windows' or 'forms'

Introduction

When you begin a program for a customer using asp.net ,you should consider about security.In web.config file you can set authentication mode value 'windows' or 'forms'.What's about difference and how you use then?(Authentication have other value.this artical not consider them.)

How to use mode windows

When you select this mode ,you can make all client access your project.Code like this(this case you can't get value using 'User.Identity.Name'):

<authentication mode="Windows" />

<authorization>
<allow users="*" />

</authorization>

other You can make make a special client to access you project with windows authentication.Code like this(this case you can get value using 'Use.Identity.Name',then you can use it to do other work you like.):

<authorization>
<deny users="?" />

</authorization>

How to use mode Forms

If you select 'Forms' mode.First you should specify a page and make sure all client can found it.Code like this:

<authentication mode="Forms">
<forms name="Authentication" loginUrl="LoginForForms.aspx" />
</authentication>

<location path="LoginForForms.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>

Second in that page you to validate the use's Id and Password.Code like this:

if(UserIsLogin())
{
try
{
FormsAuthentication.RedirectFromLoginPage("2", false);
}
catch (Exception ex)
{
Response.Redirect("defaultForForms.aspx");
}
}

Finally

This knowlege is simple for everybody.But i know this It's two years from i using C# and asp.net.So i write this article ,because i sure have many programer do know so many about it.This article must have lots of mistakes that I don't wake up to.So I welcome you tell me.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here