MVC membership, authorization, and security

Source: Internet
Author: User

Require login with authorize feature

Requires users who log on to the system to access which URLs are specified by the application. We can do this by using the authorize action filter on the controller or on a specific operation within the controller.

Authorize: feature is the default authorization filter that is available with ASP. NET MVC, which can be used to restrict user access to the action method. Applying this feature to the controller allows you to quickly apply it to each action method in the controller.

1.Authorize usage in Forms authentication and AccountController controllers

*asp.net MVC's Internet applicaton template contains a basic AccountController that supports account management for membership and OAuth authentication.

The *authorize feature is a filter, which means that it takes precedence over the execution of the associated controller operation. That is, the authorize feature first performs its primary operation in the Onauthorization method, and if the user fails to authenticate, it will produce an HTTP 401 (unauthorized) status code and redirect to the landing page defined in the application Web. config file as follows:

<authentication mode= "Forms" >

<forms loginurl= "~/account/logon" timeout= "2880" >

</authentication>

This redirect address contains a return URL so that the Account/logon operation can be redirected to the original request page after the system is successfully logged in.

All actions in the Add attribute [authorize] on *checkoutcontroller allow registered users access, but prohibit anonymous access.

Require role members to use the authorize attribute

Fh

The use of security vectors in Web applications

Fh

Defensive coding

Fh

Summarize

* Always 宎 wake up any data provided by the user

* When rendering data that is introduced as user input, HTML-encodes it, and if the data is displayed as an attribute value, it should be HTML-encoded (Html-attribute-encode))

* Consider the parts of the site that allow anonymous access, those that require authenticated access

* Do not attempt to purify the user's HTML input (using white list or other method)--otherwise it will fail

* Use http-only cookies when you do not need to access Cookic through client script (in most cases)

* Keep in mind that external input is not a form field that is displayed because it includes URL query strings, hidden form fields, Ajax requests, and external Web service results we use, etc.

* AntiXSS Library (Www.codeplex.com/AntiXSS) is highly recommended

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.