Sense/Net 6.0 Devblog
The development blog of Sense/Net 6.0
Back to Sense/Net

Efficient JSON communication in ASP.NET MVC

January 20, 2010 19:59 by Peter Zentai

A really short example on how ASP.NET MVC can be used for two-way JSON string communication.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using SenseNet.ContentRepository.Storage;
using SenseNet.ContentRepository.Storage.Security;
using System.Web.Script.Serialization;
using System.Runtime.Serialization.Json;

namespace SenseNet.Services.ContentStore
{
public class JsonFilter : ActionFilterAttribute
{
public string Param { get; set; }
public Type DataType { get; set; }

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.HttpContext.Request.ContentType.Contains("application/json"))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(DataType);
var data = ser.ReadObject(filterContext.HttpContext.Request.InputStream);
filterContext.ActionParameters[Param] = data;

}
}
}
public class SecurityController : Controller
{

public ActionResult GetACL(string path)
{
var node = Node.LoadNode(path);
var acl = node.Security.GetAcl();
return Json(acl);
}

[AcceptVerbs(HttpVerbs.Post)]
[JsonFilter(DataType = typeof(SnAccessControlList), Param = "acl")]
public ActionResult SetACL(SnAccessControlList acl)
{
var node = Node.LoadNode(acl.Path);
node.Security.SetAcl(acl);
return null;
}
}

}

Tags:

Categories: .Net
Actions: E-mail | Permalink | Comments (5) | Comment RSSRSS comment feed

Comments

March 6. 2010 19:42

Magento Development

Hello,I love reading through your blog, I wanted to leave a little comment to support you and   wish you a good continuation. Wishing you the best of luck for all your blogging efforts.

Magento Development

March 6. 2010 22:13

Wordpress Development

That is some inspirational stuff. Never knew that opinions could be this varied. Thanks for all   the enthusiasm to offer such helpful information here.

Wordpress Development

March 7. 2010 19:57

Chicago online marketing

Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I,   for one appreciate all you do!

Chicago online marketing

March 8. 2010 03:03

Chicago plumber

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very   helpful to me and I am sure to all the commenters here! It's always nice when you can not only   be informed, but also entertained! I'm sure you had fun writing this article.

Chicago plumber

March 10. 2010 15:14

Home Surveillance Security Systems

Hello, I found this blog from yahoo and read a few of your other articles. They are very informative. Pls keep on with this great work... Cheers, Steve.

Home Surveillance Security Systems

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Bookmark and Share