ASP. NET MVC Custom validation authorize Attribute (contains cookie helper)

Source: Internet
Author: User

A few days ago Insus.net has implemented a field in the database encryption and decryption of the "use of Encryptbypassphrase and decryptbypassphrase on a field of MS SQL Server encrypt and decrypt" HTTP/ Www.cnblogs.com/insus/p/5983645.html

This time insus.net the custom validation authorize Attribute in ASP.

Before implementation, insus.net changes to Usp_users_veryloginverify, instead, to better understand and use:

Source Code

OK, above is the database aspect.
Then you need to write the program in ASP. NET MVC:

Use cookies to store login and authentication information, and to write a cookie category:

Source Code


In fact, the above CookeBase.cs is a collection class that can store multiple objects. In the real program, you want to store what information, you can write a class like the following to operate:

Source Code


Next, we need to create a validation filter:


Source Code


This filter is SecurityAuthorizeAttribute.cs and we will apply it to the controller later.

Then you need to write the controller, no, we don't seem to have written a few objects, like model and entity:

Models write well, another entity, which is the object connected to the data:

In ASP., a demo of login verification is required, with a minimum of two controllers, one for anonymous users, which contains normal pages and some basic operations. Another controller is a page that can be accessed after it has been validated.

Another controller:

Finally, the view is created:

Source Code

There is one more:

Source Code


It's over, here's a live demo:

Http://www.cnblogs.com/insus/p/5994942.html

\asp.net MVC Custom Validation Authorize Attribute

ASP. NET MVC Custom validation authorize Attribute (contains cookie helper)

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.