public override void GenerateCode(AssemblyBuilder assemblyBuilder) { if (VirtualPath.EndsWith(".min.js", StringComparison.OrdinalIgnoreCase)) { base.GenerateCode(assemblyBuilder); return; } try { var virtualFile = HostingEnvironment.VirtualPathProvider.GetFile(VirtualPath); var type = virtualFile.GetType(); if (type.Name == "MapPathBasedVirtualFile") { //dynamic type cannot access protected members. var physicalPathProperty = type.GetProperty("PhysicalPath", BindingFlags.NonPublic | BindingFlags.Instance); string physicalPath = (string)physicalPathProperty.GetValue(virtualFile); string minifiedFilePath = physicalPath.Substring(0, physicalPath.Length - ".js".Length) + ".min.js"; System.IO.File.Copy(physicalPath, minifiedFilePath, true); //Minify(physicalPath); } } catch (Exception e) { } }
/// <summary> /// 获取模板类型 /// </summary> /// <returns></returns> private TemplateViewType GetTemplateViewType() { if (string.IsNullOrEmpty(VirtualPath)) { return(TemplateViewType.Page); } if (VirtualPath.EndsWith(".ascx", StringComparison.OrdinalIgnoreCase)) { return(TemplateViewType.UserControl); } return(TemplateViewType.Page); }
public IHttpHandler GetHttpHandler(RequestContext requestContext) { if (this.CheckPhysicalUrlAccess && !UrlAuthorizationModule.CheckUrlAccessForPrincipal( this.VirtualPath, requestContext.HttpContext.User, requestContext.HttpContext.Request.HttpMethod)) { throw new SecurityException(); } var page = BuildManager.CreateInstanceFromVirtualPath( this.VirtualPath, typeof(Page)) as IHttpHandler; if (page != null) { var routablePage = page as IRoutablePage; if (routablePage != null) { routablePage.Routing = new RoutingHelper(requestContext); } // The WebForm's Form.Action value may be incorrect; override it with the raw URL: var webForm = page as Page; if (webForm != null) { webForm.Load += delegate { webForm.Form.Action = requestContext.HttpContext.Request.RawUrl; } } ; } if (VirtualPath.EndsWith("Faq.asp")) { if (requestContext.RouteData.Values.ContainsKey("category") && requestContext.RouteData.Values.ContainsKey("subject")) { } } if (VirtualPath.EndsWith("Topic.aspx")) { if (requestContext.RouteData.Values.ContainsKey("username")) { var m = Membership.GetUser(requestContext.RouteData.GetRequiredString("username")); if (m != null) { var blogs = Forums.GetUserBlogTopics(-1, (int)m.ProviderUserKey); if (blogs.Count > 0) { int topicId = 0; if (requestContext.RouteData.Values.ContainsKey("subject")) { var topic = blogs.SingleOrDefault( t => t.Subject == requestContext.RouteData.GetRequiredString("subject")); if (topic != null) { topicId = topic.Id; } } else { topicId = blogs[0].Id; } if (topicId != 0) { requestContext.HttpContext.Items.Add("TopicId", topicId); } } } return(page); } else { var m = Membership.GetUser(requestContext.HttpContext.User.Identity.Name); if (m != null) { var blogs = Forums.GetUserBlogTopics(-1, (int)m.ProviderUserKey); if (blogs.Count > 0) { int topicId = 0; if (requestContext.RouteData.Values.ContainsKey("subject")) { var topic = blogs.SingleOrDefault( t => t.Subject == requestContext.RouteData.GetRequiredString("subject")); if (topic != null) { topicId = topic.Id; } } else { topicId = blogs[0].Id; } if (topicId != 0) { requestContext.HttpContext.Items.Add("TopicId", topicId); } } } return(page); } string topicSubject = requestContext.RouteData.GetRequiredString("subject"); if (topicSubject != "") { if (topicSubject.IsNumeric()) { int topicId = Convert.ToInt32(topicSubject); requestContext.HttpContext.Items.Add("TopicId", topicId); } else { var topic = Topics.GetTopicsBySubject(topicSubject); if (topic.Count == 1) { int topicId = ((SearchResult)topic[0]).Id; requestContext.HttpContext.Items.Add("TopicId", topicId); } else { requestContext.HttpContext.Items.Add("Subject", topicSubject); return ((Page) BuildManager.CreateInstanceFromVirtualPath("~/Content/Forums/Search.aspx", typeof(Page))); } } } } if (VirtualPath.EndsWith("Profile.aspx")) { string userName = requestContext.RouteData.GetRequiredString("username"); if (userName != "") { requestContext.HttpContext.Items.Add("user", userName); } } if (VirtualPath.EndsWith("Event.aspx")) { string date = requestContext.RouteData.GetRequiredString("date"); if (date != "") { requestContext.HttpContext.Items.Add("date", date); } } return(page); } }