Security and Ajax.NET Professional

Tags: .NET, AJAX, Ajax.NET, ASP.NET, Security

I have written a short example about how to use web forms security with Ajax.NET Professional. The example (C# and VB.NET) is included in the latest version available at http://www.ajaxpro.info/. Discuss the security.aspx example at Google groups. (Update: there are about 2.500 members reading and writing posts!!!)

See this example:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Security.Permissions;

public partial class SecurityCS : System.Web.UI.Page
{
  [AjaxPro.AjaxMethod]
  [PrincipalPermission(SecurityAction.Demand, Role = "Admin")]
  public static string AdminMethod()
  {
    return "Hello Admin!";
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    // Register Ajax.NET methods from this class
    AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxPro.Services.AuthenticationS­ervice));
    AjaxPro.Utility.RegisterTypeForAjax(typeof(SecurityCS));
  }

}

The AuthenticationService lets you sign in and out directly from JavaScript code:

<script type="text/javascript>
AjaxPro.Services.Authentication.Login(username, password, callback);
</script>

If you then access a AjaxMethod without the needed security rights you will get an SecurityException.

2 Comments

Comments have been disabled for this content.