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(); } } } }