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

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

问题描述

有谁知道,如果返回 JSONP 支持列于.NET 4.5的ASP.NET Web API的盒子?

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:

<一个href=\"https://www.nuget.org/packages/WebApiContrib.Formatting.Jsonp\">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使用示例可以在<一个找到href=\"http://stackoverflow.com/questions/17318144/correct-web-api-controller-action-method-definition-for-jsonp-request\">here

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

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