13693261870
2022-10-20 93b9a4bd47bfec774894928392d52a61fca07c38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Community.DAL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Http;
using System.Web.Routing;
 
namespace Community.Serve
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            SQLiteHelper.DB = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin\\App_Data\\Community.db");
            GlobalConfiguration.Configure(WebApiConfig.Register);
        }
 
        public void Application_BeginRequest(object resource, EventArgs e)
        {
            // 跨域设置:OPTIONS请求方法的主要作用:
            // 1、获取服务器支持的HTTP方法;也就是黑客经常用的方法。
            // 2、用来检查服务器的性能。如Ajax进行跨域请求是的预检,需要想另外一个域名的资源发送OPTIONS请求头,用以判断发送的请求是否安全。
            //if (Request.HttpMethod == "OPTIONS")
            //{
            //    //Response.Flush();
            //    Response.StatusCode = (int)HttpStatusCode.OK;
            //    Response.End();
            //}
 
            HttpApplication app = resource as HttpApplication;
            HttpContext context = app.Context;
            if (context.Request.HttpMethod.ToUpper() == "OPTIONS")
            {
                context.Response.StatusCode = 200;
                context.Response.End();
            }
        }
    }
}