MarkItUp.SingleUserBlog/UI/RewritingStaticFileHandler.cs

(开头部分) 2KB

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

using System;
using System.Web;
using System.IO;

/// 由liudao汉化,http://liudao.cnblogs.com
/// //该源码下载自www.51aspx.com(51aspx.com)
namespace MarkItUp.SingleUserBlog.UI
{
    // A lot of our HttpHandlers simply want to server a static file whose name is made up dynamically.
    // It would be nice if we could just derive off of StaticFileHandler to do all this for us. It will
    // handle security, conditional gets, mime mapping - everything apart from rewriting the path.
    // Unfortunately, it's an internal class, so we can't. But it's a bit odd that it is internal - it
    // gets used in the web.config file after all. Since it's ok to instantiate it from config, I reckon
    // it's ok to instantiate it from code...
    //
    // Update: It doesn't handle conditional gets. Instead, it tells the client to cache the file for 24
    // hours. A better method is needed than this, but it'll do for now.
    public abstract class RewritingStaticFileHandler : IHttpHandler
    {
        static RewritingStaticFileHandler()
        {
            Type t = Type.GetType("System.Web.StaticFileHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true);
            _staticFileHandler = (IHttpHandler)Activator.CreateInstance(t, true);
        }

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            _context = context;

            string path = NewUrlPath;
            EnsureCanonicalPath(path);
            context.RewritePath(path);
            _staticFileHandler.ProcessRequest(context);
            AmendResponse();
        }

        #endregion

        protected abstract string NewUrlPath
        {
            get;
        }

        protected virtual void AmendResponse()
        {
        }

        protected HttpContext Context
        {
            get { return _context; }
        }

        private void EnsureCanonicalPath(string path)
后面还有 15 行代码,解锁后查看完整代码

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

AI 解读

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

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