Skip to content

Instantly share code, notes, and snippets.

function api_test(url, type, data, callback) {
$.ajax(
{
url: url,
type: type,
processData: false,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
dataType: 'json',
async: false,
namespace MyNamespace {
public static class MyHelper
{
public static MvcHtmlString MyHelper(this HtmlHelper helper)
{
return helper.AntiForgeryToken();
}
}
}
Watcher:
(wood) Watch at least one repository
(bronze) Watcher more than 10
(silver) Watcher more than 100
(gold) Watcher more than 500
Follower:
(wood) Follow at least one person
(bronze) Follow more than 10 people
(silver) Follow more than 100 people
public class HostedByCheckAttribute : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext) {
var postId = filterContext.ActionParameters["id"] as int;
var postsRepo = new PostsRepository();
var post = postsRepo.Get(postId);
if (!post.IsHostedBy(/* ... */)) {
filterContext.Result = new ViewResult { ViewName = "InvalidOwner", ViewBag = filterContext.Controller.ViewBag, ViewData = filterContext.Controller.ViewData };
}
public class Attribute : ActionFilterAttribute {
public override void OnActionExecuted(ActionExecutedContext filterContext) {
base.OnActionExecuted(filterContext);
if (!filterContext.ExceptionHandled) {
var exception = filterContext.Exception;
if (exception is CustomException) {
filterContext.Controller.ViewData.ModelState.Add(String.Empty, Resource.CustomExceptionMessage);
}
@alexbeletsky
alexbeletsky / gist:1259608
Created October 3, 2011 17:06
Running SSH under web application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Diagnostics;
using System.IO;
// Please try to run both: Cassini and IIS.
// For IIS select Application Pool with Process Identity == Your identity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcForDebug2.Infrastructure {
public class ServiceAttribute : ActionFilterAttribute {
public override void OnActionExecuted(ActionExecutedContext filterContext) {
if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) {
@alexbeletsky
alexbeletsky / gist:1325577
Created October 30, 2011 06:19
ASP.NET MVC2 Views web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
public interface IMapper<TInput, TOutput>
{
TOutput Map(TInput input);
}
public interface ICompositeMapper<TInput, TOutput>
{
TOutput[] Map(TInput input);
}
@alexbeletsky
alexbeletsky / gist:1722396
Created February 2, 2012 08:44
Moq and NSubstitute tests
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NSubstitute;
using Moq;
namespace NewTools
{