.net 4.5 ASP.Net Web API JSONP 支持 [英] .net 4.5 ASP.Net web API JSONP support

查看:41
本文介绍了.net 4.5 ASP.Net Web API JSONP 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道在 .net 4.5 ASP.NET WEB API 中是否支持立即返回 JSONP?

Does anyone know if returning JSONP is supported out of the box in .net 4.5 ASP.NET WEB API?

对于 MVC 或 .net 的早期版本,我发现了很多自己动手",但似乎没有任何特定于更高版本的东西.

I've found plenty of "roll your own" for earlier versions of MVC or .net but there doesn't seem to be anything specific to later versions.

我意识到这可能是因为它们的早期版本可以与 .net 4.5 堆栈一起使用,但我很好奇是否有人已经加入.

I realize this could be because they earlier versions will work with .net 4.5 stack but I'm curious if someone has already been baked in.

推荐答案

据我所知你必须得到 jsonp 格式化程序.这是其中一种实现:

As far as I know you must get the jsonp formatter. Here is one of the implementations:

http://nuget.org/packages/WebApi.JsonP

更新

推荐的包现在由WebApiContrib团队提供:

The recommended package is provided now by WebApiContrib team:

https://www.nuget.org/packages/WebApiContrib.Formatting.Jsonp

在应用程序启动时将其添加到 Global.asax:

Add it to Global.asax on application start:

GlobalConfiguration.Configuration.Formatters.Insert(0,  new JsonpMediaTypeFormatter(new JsonMediaTypeFormatter()));

jquery 的使用示例可以在 中找到这里

Example of usage with jquery can be found in here

这篇关于.net 4.5 ASP.Net Web API JSONP 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆