FormAuthentication is very popular method among developers to perform logging in and out.

Many developers prefer to save user related details in separate database like SQL Sever, Oracle, DB2, etc. Rather than placing it in web.config or seperate XML file. So I'll show you how to do that in step-by-step manner:

Step 1: Do following entries in web.config under <system.web>

Web.config   File

------------------------------------------

<authentication mode="Forms">
            <forms name="AuthCookie"
                path="/"
                loginUrl="login.aspx"
                protection="All"
                timeout="60">
            </forms>
        </authentication>
        <authorization>
            <deny users="?" />
        </authorization>

Where, loginUrl is name of your custom login web page with two textboxes and login button control.  (user name, password textboxes).

 

Step 2: Add Login.aspx web page

In this page add 2 textboxes, 2 labels and one button control. This is where user will enter user name and password to browse your website.

 

Step 3: On Login button click event add following code

If SharedClass.Authenticate(txtUser.Text, txtPassword.Text) Then

FormsAuthentication.RedirectFromLoginPage(txtUser.Text, False)

Else

 ' Add code to Display error message to user

End If

Step 3: Add  SharedClass to your website (VB class File) with one Shared method named "Authenticate"

Public Shared Function Authenticate(UserName as string, Password as string) as Boolean

   'Here write your database related code to check user name and password. Return True if both matches.

End Function

Step 4: To do Log Off

To perform logging off operation add following code on other page or simply place log off button on master page with following code.

FormsAuthentication.SignOut()

Response.Redirect("urlName.aspx")

 

That's All Folks!

Posted by kuldeep deokule | with no comments

To download presentations in TechEd 2006 visit following links:

http://www.wintoolzone.com/showpage.aspx?url%3dhttp://www.wintoolzone.com/Presentations.aspx

http://www.wintoolzone.com/blog/?cat=18

http://www.wintoolzone.com/blog/?cat=25

Posted by kuldeep deokule | with no comments

Welcome .NET 3.0!

In simple words .NET 3.0 means more managed code. Formally .NET 3.0 known as WinFX. So its just renaming of WinFX that consists of following components inside it known as .NET 3.0 framework.
 
1. .NET Framework 2.0
Common Language Runtime (CLR)
Base Class Library
ADO.NET 2.0, ASP.NET 2.0, Windows Forms 2.0
VB 8.0 and C# 2.0
2. WinFX
Windows Communication Foundation (WCF)
Windows Presentation Foundation (WPF)
Windows Workflow Foundation (WF)
3. InfoCard
Renamed to Windows CardSpace (WCS)


To know more about .NET 3.0, to get samples refer to following links:
http://blogs.msdn.com/brada/archive/2006/06/10/625717.aspx
http://www.netfx3.com/


 

Posted by kuldeep deokule | with no comments

One of the limitation of data source controls that they destroy static items created earlier. Most websites need static items in list type controls. So in ASP.NET 1.x many developers prefer to write static item addition code in Page_Load event as shown below:


Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            'Set up the data binding.
            NewsletterList.DataSource = SqlDataSource1
            NewsletterList.DataTextField = "newsletter"
            NewsletterList.DataValueField = "id"
            NewsletterList.DataBind()
 

            'Add following items and select the first item by default.
            NewsletterList.Items.Insert(0, "Select")
            NewsletterList.Items.Insert(1, "Send All Newsletters")
            NewsletterList.SelectedIndex=0
        End If
End Sub

ASP.NET 2.0 exposes new AppendDataBoundItems property for all list type controls. This property makes this task little easier. If AppendDataBoundItems property is set to true for DropdownList control. Then added static items are not destroyed at the time of page load.
Just take look at following code:

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            'Set up the data binding.
           
     NewsletterList.Items.Add("Select")      
     NewsletterList.Items.Add("Send All Newsletters")
     NewsletterList.AppendDataBoundItems = True
     NewsletterList.DataSource = SqlDataSource1
            NewsletterList.DataTextField = "newsletter"
            NewsletterList.DataValueField = "id"
            NewsletterList.DataBind()
 
            NewsletterList.SelectedIndex=0
        End If
End Sub

If you set AppendDataBoundItems property to False then all static items will be destroyed. Value of AppendDataBoundItems is stored in view state.
 So AppendDataBoundItems attribute will do all magic for us. AppendDataBoundItems attribute is only available in .NET framework 2.0. So for ASP.NET 1.x you have to rely on earlier page_load solution.

Posted by kuldeep deokule | with no comments
Navigate to link below to read more on improve Data caching in ASP.NET 2.0.

http://dotnetslackers.com/community/blogs/kuldeepdeokule/archive/2006/06/22/74.aspx
Posted by kuldeep deokule | with no comments
The views expressed on this weblog are mine and do not necessarily reflect the views of my employer.

All postings are provided "AS IS" with no warranties, and confer no rights.
Posted by kuldeep deokule | with no comments