Example of using forms authentication in asp.net

Source: Internet
Author: User

Recently, a small asp.net project was started. You need to log on to the entire project to perform operations. In the past, we used asp session + cookie to implement identity authentication. I have long heard of the forms authentication provided by asp.net, but I have never practiced it. Today I just caught the opportunity to apply it.

Problem: It is said that using forms authentication cannot get more information about the current Login User except the user name. After some small experiments, the userdata that comes with forms can be used as a place for us. The following is a record of my operation steps.

Step 1: Key Points of web. config Configuration:

Copy to ClipboardReference content: [www.bkjia.com] web. config Configuration
1 <! --
2. You can use the <authentication> section to configure ASP. NET
3. Identify
4. Security Authentication mode.
5 -->
6 <authentication mode = "Forms">
7 <forms loginUrl = "login. aspx" defaultUrl = "index. aspx"
8 name = ". ztinfozero" path = "/Manager"
9 slidingExpiration = "true" timeout = "10"> </forms>
10 </authentication>
11 <authorization>
12 <deny users = "? "/>
13 </authorization>

Step 2: Construct SiteUser Model

Copy to ClipboardReference: [www.bkjia.com] TopicUser Model
[Serializable]
Public class TopicUser
{
Public TopicUser (){}

Model # region model
Private System. Int32 _ autoID;
/** // <Summary>
///
/// </Summary>
Public System. Int32 autoID
{
Get {return _ autoID ;}
Set {_ autoID = value ;}
}
Private System. String _ UserName;
/** // <Summary>
/// User Name
/// </Summary>
Public System. String UserName
{
Get {return _ UserName ;}
Set {_ UserName = value ;}
}
Private System. String _ UserChName;
/** // <Summary>
/// Real name
/// </Summary>
Public System. String UserChName
{
Get {return _ UserChName ;}
Set {_ UserChName = value ;}
}
Private System. String _ UserPass;
/** // <Summary>
///
/// </Summary>
Public System. String UserPass
{
Get {return _ UserPass ;}
Set {_ UserPass = value ;}
}
Private System. String _ DepartMent;
/** // <Summary>
///
/// </Summary>
Public System. String DepartMent
{
Get {return _ DepartMent ;}
Set {_ DepartMent = value ;}
}
Private System. String _ Duty;
/** // <Summary>
///
/// </Summary>
Public System. String Duty
{
Get {return _ Duty ;}
Set {_ Duty = value ;}
}

Private System. Int32 _ UserPermit;
/** // <Summary>
///
/// </Summary>
Public System. Int32 UserPermit
{
Get {return _ UserPermit ;}
Set {_ UserPermit = value ;}
}
Private System. Int32 _ Status;
/** // <Summary>
///
/// </Summary>
Public System. Int32 Status
{
Get {return _ Status ;}
Set {_ Status = value ;}
}
# Endregion
}

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.