123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using System.Collections.Generic;
- using System.Data.Entity.Core.Mapping;
- using System.Data.Entity.Core.Metadata.Edm;
- using System.Data.Entity.Infrastructure;
- using System.Linq;
- using System.Reflection;
- using System.Web;
- using System.Web.Mvc;
- using System.Web.Optimization;
- using System.Web.Routing;
- using Autofac;
- using Autofac.Integration.Mvc;
- using EMISOnline.Utility;
- using System.Resources;
- namespace EMISOnline.Web
- {
- // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,
- // 请访问 http://go.microsoft.com/?LinkId=9394801
- public class MvcApplication : System.Web.HttpApplication, IAutofacContainerProvider
- {
- static IContainer _container;
- public IContainer Container
- {
- get { return _container; }
- set { _container = value; }
- }
- protected void Application_Start()
- {
- var viewEngines = ViewEngines.Engines;
- var webFormEngines = viewEngines.OfType<WebFormViewEngine>().FirstOrDefault();
- if (webFormEngines != null)
- {
- viewEngines.Remove(webFormEngines);
- }
- AreaRegistration.RegisterAllAreas();
- BundleTable.EnableOptimizations = true;
- //WebApiConfig.Register(GlobalConfiguration.Configuration);
- FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
- RouteConfig.RegisterRoutes(RouteTable.Routes);
- BundleConfig.RegisterBundles(BundleTable.Bundles);
- //AuthConfig.RegisterAuth();
- var builder = new ContainerBuilder();
- builder.RegisterModule<EMISOnline.CommonLogic.DALModule>();
- builder.RegisterModule<EMISOnline.CommonLogic.ServiceModule>();
- builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
- var _container = builder.Build();
- AutofacHelper.Container = _container;
- DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(_container));
- //EF优化代码
- using (Entities.EMISOnlineContextContainer dbContext = new Entities.EMISOnlineContextContainer())
- {
- var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
- var mappintCollection = (StorageMappingItemCollection)objectContext.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
- mappintCollection.GenerateViews(new List<EdmSchemaError>());
- }
- //ViewEngines.Engines.Clear();
- //ViewEngines.Engines.Add(new EcViewEngine());
- }
- //public sealed class EcViewEngine : RazorViewEngine
- //{
- // public EcViewEngine()
- // {
- // ViewLocationFormats = new[]
- // {
- // "~/Views/{1}/{0}.cshtml",//系统默认规则
- // "~/Views/Shared/{0}.cshtml",//系统默认规则
- // "~/Views/CalendarManage/{1}/{0}.cshtml",//我们的规则
- // "~/Views/EvaluationManage/{1}/{0}.cshtml",//我们的规则
- // };
- // }
- // public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
- // {
- // return base.FindView(controllerContext, viewName, masterName, useCache);
- // }
- //}
- ///// <summary>
- ///// 验证处理 IPrinceple
- ///// 将保存在票据中的信息转为当前的用户信息
- /////
- ///// </summary>
- ///// <param name="sender"></param>
- ///// <param name="e"></param>
- //protected void Application_AuthenticateRequest(Object sender, EventArgs e)
- //{
- // FormsAuthenticationHelper fahelper = new FormsAuthenticationHelper();
- // List<string> lurl = new List<string>();
- // lurl.Add("Content/");
- // lurl.Add("Doc/");
- // lurl.Add("Scripts/");
- // lurl.Add("Login/");
- // lurl.Add("UploadFile/");
- // var cookieName = EMIS.Utility.Const.LOCAL_SETTING_LOGIN_COOKIENAME;
- // fahelper.AuthenticateRequest(Context, cookieName, lurl);
- //}
- //void Application_BeginRequest(object sender, EventArgs e)
- //{
- // try
- // {
- // string session_param_name = "ASPSESSID";
- // string session_cookie_name = EMIS.Utility.Const.LOCAL_SETTING_LOGIN_COOKIENAME;
- // if (HttpContext.Current.Request.Form[session_param_name] != null)
- // {
- // UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
- // }
- // else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
- // {
- // UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
- // }
- // }
- // catch
- // {
- // }
- // //此处是身份验证
- // try
- // {
- // string auth_param_name = "AUTHID";
- // string auth_cookie_name = FormsAuthentication.FormsCookieName;
- // if (HttpContext.Current.Request.Form[auth_param_name] != null)
- // {
- // UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
- // }
- // else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
- // {
- // UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
- // }
- // }
- // catch { }
- //}
- private void UpdateCookie(string cookie_name, string cookie_value)
- {
- HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
- if (null == cookie)
- {
- cookie = new HttpCookie(cookie_name);
- }
- cookie.Value = cookie_value;
- HttpContext.Current.Request.Cookies.Set(cookie);//重新设定请求中的cookie值,将服务器端的session值赋值给它
- }
- }
-
- }
|