MarkItUp.SingleUserBlog/UI/Portal/WebPartsAdministrator.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.Compilation;

namespace MarkItUp.SingleUserBlog.UI.WebParts {

    public static class WebPartsAdministrator {

        public static WebPartCollection GetWebParts(
                string path, HttpContext context) {

            // Instantiate the target page dynamically
            Page page = (Page)BuildManager.
                CreateInstanceFromVirtualPath(path, typeof(Page));

            // Extract WebParts from target page
            WebPartCollection webParts = null;
            page.PreLoad += delegate {
                webParts = WebPartManager.
                    GetCurrentWebPartManager(page).WebParts;
            };

            // Execute target page from within admin page
            ExecutePage(page, path, context);

            return webParts;
        }

        private static void ExecutePage(Page page, string path,
                                        HttpContext context) {
            // Set path to target page
            string originalPath = context.Request.Path;
            context.RewritePath(path);

            try {
                // Execute target page
                context.Server.Execute(page, TextWriter.Null, false);
            } catch {
                // Trap exceptions so they do not affect the
                // admin page.
            }

            // Set path back to admin page
            context.RewritePath(originalPath);
        }

        public static void DeleteWebPart(string path, string ID,
                                         HttpContext context) {
            // Instantiate the target page dynamically
            Page page = (Page)BuildManager.
                CreateInstanceFromVirtualPath(path, typeof(Page));

后面还有 13 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。