天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

179 lines
6.5 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Configuration;
using QMAPP.ServicesAgent;
using System.Web.Configuration;
namespace QMAPP.Web
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
/// <summary>
/// 应用程序对象
/// </summary>
public class MvcApplication : System.Web.HttpApplication
{
/// <summary>
/// 数据分页尺寸
/// </summary>
public static int PageSize { get; set; }
/// <summary>
/// 应用程序物理路径
/// </summary>
public static string PhysicsRootPath { get; set; }
//FJCRoot 物理路径
public static string FJCRoot { get; set; }
/// <summary>
/// 临时文件路径
/// </summary>
public static string TempPath { get; set; }
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Login", id = UrlParameter.Optional } // Parameter defaults
);
}
/// <summary>
/// 应用启动
/// </summary>
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
//配置日志处理组件
QMFrameWork.Log.LogManager.Configure("log4net");
try
{
//应用程序物理路径
PhysicsRootPath = Server.MapPath(HttpRuntime.AppDomainAppVirtualPath);
//主程序路径
FJCRoot = ConfigurationManager.AppSettings["FJCRoot"].ToString();
//临时文件路径
TempPath = PhysicsRootPath + "Temp\\";
if (System.IO.Directory.Exists(PhysicsRootPath + "Temp") == false)
{
System.IO.Directory.CreateDirectory(PhysicsRootPath + "Temp");
}
//设置文件操作路径
QMFrameWork.WebUI.Util.IEFileTool.TempPath = TempPath;
QMFrameWork.Common.ExcelOperation.IEExcelHelper.FilePath = Server.MapPath("~/App_Data/Excel/");
QMAPP.Common.Web.Controllers.PrintController.TemplatePath = Server.MapPath("~/App_Data/Print/");
//多语言
//QMFrameWork.Common.MLanguage.LanguageHelper.Config();
//设置数据分页尺寸
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["PageSize"]) == false)
PageSize = int.Parse(ConfigurationManager.AppSettings["PageSize"]);
else
PageSize = 15;
//加载静态基础数据
QMFrameWork.Common.Util.ModelDictionaryHandler.Configure();
//设置菜单文件路径
QMFrameWork.WebUI.Menu.MenuHelper.MenuFilePath = Server.MapPath("~/App_Data/Menu.xml");
//设置主应用路径
QMAPP.Common.Web.Controllers.QController.ManageCenterRoot = ConfigurationManager.AppSettings["ManageCenterRoot"].ToString();
QMAPP.Common.Web.Controllers.QController.PhysicsRootPath = PhysicsRootPath;
//初始化服务
ServiceAgent.Init();
//加载字段帮助提示
//记录日志
QMFrameWork.Log.LogManager.LogHelper.Info(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "应用启动"});
}
catch (Exception ex)
{
if (QMFrameWork.Log.LogManager.LogHelper != null)
{
QMFrameWork.Log.LogManager.LogHelper.Error(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "应用启动",ErrorInfo=ex });
}
throw ex;
}
}
protected void Application_Error(object sender, EventArgs e)
{
//Exception ex = Server.GetLastError();
//RouteData routeData = new RouteData();
//routeData.Values.Add("controller", "Error");
//if (ex == null)
//{
// ex = new Exception("系统异常");
//}
//routeData.Values.Add("action", "ShowException");
//routeData.Values.Add("error", ex);
//Server.ClearError();
//IController errorController = new QMAPP.Common.Controllers.ErrorController();
//errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
}
/// <summary>
/// 应用停止
/// </summary>
protected void Application_End()
{
}
void Application_BeginRequest(object sender, EventArgs e)
{
//本代码的功能是检查页面请求的大小,如果超过了配置文件maxRequestLength的设定值,就提示用户超过了所允许的文件大小。
//从配置文件里得到配置的允许上传的文件大小
HttpRuntimeSection runTime = (HttpRuntimeSection)WebConfigurationManager.GetSection("system.web/httpRuntime");
//maxRequestLength 为整个页面的大小,不仅仅是上传文件的大小,所以扣除 100KB 的大小,
//maxRequestLength单位为KB
int maxRequestLength = (runTime.MaxRequestLength) * 1024;
//当前请求上下文的HttpApplication实例
//HttpContext context = ((HttpApplication)sender).Context;
//判断请求的内容长度是否超过了设置的字节数
if (Request.ContentLength > maxRequestLength)
{
//注意这里可以跳转,可以直接终止;在VS里调试时候得不到想要的结果,通过IIS才能得到想要的结果;FW4.0经典或集成都没问题
//Response.Write("请求大小" + Request.ContentLength);
Response.Write("<script>alert('请求大小超过" + maxRequestLength + ");</script>");
Response.End();
}
}
}
}