Files
T-DAS/Epost.TestToolsWeb/Global.asax.cs
2023-04-20 16:36:30 +08:00

50 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Epost.Common;
using Epost.TestToolsWeb.App_Start;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Timers;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace Epost.TestToolsWeb
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
/// <summary>
/// 跨域设置
/// </summary>
public void Application_BeginRequest()
{
//OPTIONS请求方法的主要作用
//1、获取服务器支持的HTTP方法也就是黑客经常用的方法。
//2、用来检查服务器的性能。如Ajax进行跨域请求是的预检需要想另外一个域名的资源发送OPTIONS请求头用以判断发送的请求是否安全
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
{
//表示对输出的内容进行缓冲执行page.Response.Flush()时,会等所有内容缓冲完毕,将内容发送到客户端
//这样就不会出错,造成页面卡死状态,让用户无限制等下去
Response.Flush();
}
}
}
}