Ajaxpro New Discovery (1): authenticationservice

Source: Internet
Author: User

Ajaxpro has been used for some time. It seems that although ajaxpro is not as powerful as Asp.net Ajax, It is enough. Most of the users are concerned that this framework is terminated in Asp.net 1.x. however, when I know this framework, the latest version is well supported. some new features of net2.0, such as authenticationservice (membership) and profileservice. in this series, I will summarize some new discoveries over the past period, including servers and clients. Here I need to tell you that the ajaxpro client is also worth mentioning.

The content I will introduce here is based on your understanding of ajaxpro.

Authentication Service

The membership management is. A new feature in net2.0, which provides role-based authentication and access control, stores user information through cookies on the client, and also uses cookiless, ajaxpro can only be used for Cookie Authentication

First download the ajaxpro framework that supports. net2.0 and register httphandler in Web. config.

<! -- HTTP handler for ajaxpro -->
<Httphandlers>
<Add verb = "*" Path = "*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro.2"/>
</Httphandlers>

Register ajaxpro. Services. authenticationservice on the page:

// Ajaxproauthenticationservice. aspx. CS
Public partial class ajaxproservices: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Ajaxpro. Utility. registertypeforajax (typeof (ajaxpro. Services. authenticationservice ));
Ajaxpro. Utility. registertypeforajax (typeof (ajaxproservices ));
}
}

The client can use the following three methods:

  • Ajaxpro. Services. Authentication. login (username, password, callback.
  • Ajaxpro. Services. Authentication. validuser (callback): Check whether the identity is passed. The callback parameter result. Value returns true/false.
  • Ajaxpro. Services. Authentication. logout (); the user logs out and does not need a callback function.
Method-based permission Control

In ajaxpro that supports. net2.0, you can control the access permission of client methods. Michael Schwarz provides such a method in his document.

[Ajaxpro. ajaxmethod]
[Principalpermission (securityaction. Demand, role = "admin")]
[Principalpermission (securityaction. Deny, name = "? ")]
Public datetime getservertime ()
{
Return datetime. now;
}

Principalpermissionattribute can be used to claim that the user running your code belongs to a specified role or has been authenticated. The preceding method allows the role admin to access and denies anonymous user access, this method is not limited to ajaxpro. used in the net2.0 environment. its tag attributes include:

  • Action: securityaction Enumeration type. The values can be assert, demand, inheritancedemand, linkdemand, permitonly, requestminimum, requestoptional, and requestrefuse.
  • Role: role name that is allowed or denied
  • Name: Permission control for a user. * indicates all ,? Anonymous.
  • Authenticated: True/false, whether authentication is required
  • Unrestricted: True/false unlimited access

Compared with Asp.net Ajax, ajaxpro is relatively simple to use and has different functions. If authenticationservice is available, it will naturally have profileservice, which will be introduced in the next 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.