Login control details

Source: Internet
Author: User

Microsoft has provided a permission management mechanism since ASP. NET 2.0,

This mechanism is mainly implemented by membership and role,

Of course, Microsoft has always been good at providing directly used controls,

Therefore, Microsoft also has ready-made controls for permission management,

First, log on to the login control,

Previous two articlesArticleWe also mentioned that to use membership and role for permission management,

You must first register a database for this website (read the previous two blog posts if you do not know ),

Of course, you must first specify a website database for login,

Otherwise, the ghost knows where to match the user name and password,

Therefore, you must register the website database first (this content is included in the previous article)

After registration,

11 data tables and N-plus stored procedures will be created in the database you specified

To complete the permission management mechanism provided by Microsoft,

There should be approximately 60-60 stored procedures ~ 100,

By the way, let's explain why there are so many stored procedures,

In fact, Microsoft is an open mode to implement the membership and role permission management mechanisms,

If you write all the SQL names directly in the class method, this will become very dead,

If I change the database, what should I do if I use Oracle? Then these classes are useless,

If I write it as a stored procedure, if I change it to an Oracle database,

Then, I just need to modify these stored procedures.

The database has changed from SQL Server to Oracle.

Also, modify the Web. config Authentication Mode to form authentication. Otherwise, an error occurs,

You don't know what's going on !!!

When using the login control, another point that needs to be declared is,

For user authentication,

It is not implemented by the login control, but is supported by membership and role,

What the login control does can be said to be a UI, And then it accepts parameters such as username and password,

Then pass these parameters to the membership and role classes for processing,

Therefore, what is working is membership and role, rather than the login control itself.

Next, let's introduce the attributes and events of the login control,


Distinationpageurl --------- specifies the page to jump to when the user logs on successfully.

Failureaction ------------- specifies the action to take when the logon fails,

There are two options: refresh and redirecttologinpage.

Many other properties are not directly visible in the Property Window,

You can use msdn to view or directly callCodeDefinition window,

Let's look at several major events.

Authenticate -------- custom verification. The default membership and role are not applicable for verification,

Write the ADO. Net code for verification.

Loggingin ----------- operation performed when the user presses the logon button (verification is not performed yet)

Loggedin ------------ triggered when the user presses the logon button and passes the verification

Logginerror ---------- events that occur during verification

Some of the above attributes are explained as follows:

The first is distinationpageurl. If this attribute is not set,

After successfully logging on with login,

Will automatically jump to the defaulturl defined in Web. config

If you have defined distinationpageurl,

After successful logon, the page defined by distinationpageurl is displayed,

It does not jump to the page specified by defaulturl defined in Web. config.

You can also convert the login control into a template,

In this way, you can fully customize the login user interface,

Next, let's look at a demo that uses login.

First, I have defined three pages.

One is login. aspx.

One is main. aspx.

One is demo _ 2. aspx

Then let's take a look at some configurations in Web. config,

From the configuration, we can see that I have set the loginurl attribute,

This attribute is used when the user does not pass the verification,

Use formsauthentication. redirecttologinpage (); to jump to the page,

Then I defined defaurl URL and explained the use of this attribute.

The page to jump to when the user passes the verification and does not set destinationpageurl,

Then there is the path attribute. Path = "/" indicates that the local localhost is used,

In fact, there are many important attributes in this forms tag, but you can guess a rough idea based on the name,

Then, I add a login control in login. aspx and convert it to a template,

Set the appearance property,

The following interface is displayed.

Let's take a look at the code-behind and demo _ 2. aspx code-behind of Main. aspx,

(The two codes-behind are the same)

Next, let's take a look at the demo,

First, I first browsed the demo _ 2. ASPX page and found that it will automatically jump to the login. ASPX page,

(This is because the loginurl set in Web. config has a function)

Then I log on to the Apsara stack console. After Successful Logon, the system automatically jumps to the demo _ 2. ASPX page,

Then, I directly used the login. ASPX page. At the beginning, I browsed the login. ASPX page,

After successful logon, it will automatically jump to main. aspx,

(This is the role of the destinationpageurl attribute)

The above is just a simple introduction to the login control,

However, for some of the notes, such as the settings in Web. config,

Pay attention to it,

In fact, the functions of the login control are far more than that. If you are interested, you can study it carefully.



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.