ie8/9收到json資料後提示下載的解決方法
使用fineuploader上傳檔案,收到處理程式的返回結果為json資料,在google和ie10及以上沒有問題,但在ie8、ie9下提示下載json,為避免出現提示下載框,
修改檔案Global.asax.cs中增加
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedMediaTypes.Clear();
遮蔽xml和json即可。也可只遮蔽json。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using log4net;
using Zephyr.Core;
namespace Zephyr.Web
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
FrameworkConfig.Register();
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedMediaTypes.Clear();
}
}
}