(Applicable to SQL Server Management Studio 2008 R2)
Windows 7:
C:\Users\username\AppData\Roaming\Microsoft\SQL Profiler\10.0\Templates\Microsoft SQL Server\90\
Windows XP:
C:\Documents and Settings\username\Application Data\Microsoft\SQL Profiler\10.0\Templates\Microsoft SQL Server\90
Or search for:
*.tdf
MVC2: Jsonp callback not firing
Jsonp callback not firing, ASP.NET MVC2.
Custom Jsonp Classes:
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
namespace YourNamespace
{
public class JsonpResult : JsonResult
{
public string Callback { get; set; }
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
HttpResponseBase response = context.HttpContext.Response;
if (!String.IsNullOrEmpty(ContentType))
response.ContentType = ContentType;
else
response.ContentType = "application/json";
if (ContentEncoding != null)
response.ContentEncoding = ContentEncoding;
if (Callback == null || Callback.Length == 0)
Callback = context.HttpContext.Request.QueryString["callback"];
if (Data != null)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string ser = serializer.Serialize(Data);
response.Write(Callback + "(" + ser + ");");
}
}
}
public class JsonpFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext == null)
throw new ArgumentNullException("filterContext");
string callback = filterContext.HttpContext.Request.QueryString["callback"];
if (callback != null && callback.Length > 0)
{
JsonResult result = filterContext.Result as JsonResult;
if (result == null)
{
throw new InvalidOperationException("JsonpFilterAttribute must be applied only " +
"on controllers and actions that return a JsonResult object.");
}
filterContext.Result = new JsonpResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
ContentEncoding = result.ContentEncoding,
ContentType = result.ContentType,
Data = result.Data,
Callback = callback
};
}
}
}
}
Controller:
using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace YourNamespace.Controllers
{
public class YourController : Controller
{
[JsonpFilter]
public JsonResult JsonpLookup(string term)
{
return new JsonpResult
{
Data = new { Value = "You passed this value: " + term }
};
}
}
}
Implementation:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<input type="text" id="term" name="term" value="" />
<input type="button" onclick="jsonp_test()" value="Test" />
<script type="text/javascript">
function jsonp_test() {
$.ajax({
type: "GET",
url: "http://www.yourremotesite.com/YourController/JsonpLookup",
dataType: "jsonp",
crossDomain: true,
data: { term: $("#term").val() },
success: function (data) {
alert(data.Value);
}
});
}
</body>
</html>
Subscribe to:
Posts (Atom)