ImageHandler.ashx

(开头部分) 6KB

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

<%@ WebHandler Language="C#" Class="ImageHandler" %>

//===============================================================================================
//
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.
//
//===============================================================================================

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.IO;
using System.Web.Caching;
using System.Drawing.Drawing2D;
using MyWebPagesStarterKit;

/// <summary>
/// This handler serves (resized) images out of the "~/App_Data/_Downloads/" folder.
/// </summary>
public class ImageHandler : IHttpHandler
{
    #region IHttpHandler Members

    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        try
        {
            //get the sectionId
            string section = context.Request.QueryString["section"];
            //get the filename
            string file = context.Request.QueryString["image"];
            string path = string.Empty;

            // get the pageId for the authentication
            string pageId = context.Request.QueryString["pg"];

            if (section != null)
            {
                //user authentication:
                WebPage _page = new WebPage(pageId);
                if (_page.AllowAnonymousAccess == false && context.User.Identity.IsAuthenticated == false)
                    throw new Exception("User is not allowed to view this file");
                
                //create the path (when sectionId is present)
                path = context.Server.MapPath(string.Format("~/App_Data/_Downloads/{0}/{1}", section, file));
            }
            else
            {
                //create the path (when no sectionId is present)
                path = context.Request.MapPath(file);
            }
后面还有 129 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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