Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用HttpHandlerFactory呈现CMS和物理页面 我在编写CMS系统的过程中,在阅读和处理了几个例子之后,我决定去执行我需要的东西。_C#_Asp.net_Httphandler_Ihttphandler_Httphandlerfactory - Fatal编程技术网

C# 使用HttpHandlerFactory呈现CMS和物理页面 我在编写CMS系统的过程中,在阅读和处理了几个例子之后,我决定去执行我需要的东西。

C# 使用HttpHandlerFactory呈现CMS和物理页面 我在编写CMS系统的过程中,在阅读和处理了几个例子之后,我决定去执行我需要的东西。,c#,asp.net,httphandler,ihttphandler,httphandlerfactory,C#,Asp.net,Httphandler,Ihttphandler,Httphandlerfactory,关键是我们的网站通常是复制和注册过程的混合体。因此,我目前需要使用默认的HttpHandler for aspx来呈现物理注册页面,直到我能够找到一种方法来管理它们 创建处理程序类后,我将以下内容添加到网站的web配置中 <add verb="*" path="*.aspx" type="Web.Helpers.HttpCMSHandlerFactory, Web.Helpers"/> 我的问题是,当存在物理页面时,我是否应该使用除PageParser.GetCompiledPag

关键是我们的网站通常是复制和注册过程的混合体。因此,我目前需要使用默认的HttpHandler for aspx来呈现物理注册页面,直到我能够找到一种方法来管理它们

创建处理程序类后,我将以下内容添加到网站的web配置中

<add verb="*" path="*.aspx" type="Web.Helpers.HttpCMSHandlerFactory, Web.Helpers"/>
我的问题是,当存在物理页面时,我是否应该使用除
PageParser.GetCompiledPageInstance
以外的东西

更新:从上面开始,我继续为图像开发和使用HttpHandler,它同样基于相同的原理工作,即如果图像存在,则使用数据库中的其他服务。png文件有点问题,但下面的过程适用于所示的文件格式

        byte[] image = null;
        if (File.Exists(context.Request.PhysicalPath))
        {
            FileStream fs = new FileStream(context.Request.PhysicalPath, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            image = br.ReadBytes((int)fs.Length);
        }
        else
        {
            IKernel kernel = new StandardKernel(new ServiceModule());
            var cmsImageService = kernel.Get<IContentManagementService>();
            var framework = FrameworkSetup.GetSetFrameworkSettings();
            image = cmsImageService.GetImage(Path.GetFileName(context.Request.PhysicalPath), framework.EventId);
        }

        var contextType = "image/jpg";
        var format = ImageFormat.Jpeg;

        switch (Path.GetExtension(context.Request.PhysicalPath).ToLower())
        {
            case ".gif":
                contextType = "image/gif";
                format = ImageFormat.Gif;
                goto default;
            case ".jpeg":
            case ".jpg":
                contextType = "image/jpeg";
                format = ImageFormat.Jpeg;
                goto default;
            case ".png":
                contextType = "image/png";
                format = ImageFormat.Png;
                goto default;
            default:
                context.Cache.Insert(context.Request.PhysicalPath, image);
                context.Response.ContentType = contextType;
                context.Response.BinaryWrite(image);
                context.Response.Flush();
                break;
        }
byte[]image=null;
if(File.Exists(context.Request.PhysicalPath))
{
FileStream fs=newfilestream(context.Request.PhysicalPath,FileMode.Open,FileAccess.Read);
BinaryReader br=新的BinaryReader(fs);
image=br.ReadBytes((int)fs.Length);
}
其他的
{
IKernel kernel=新的标准内核(新的ServiceModule());
var cmsImageService=kernel.Get();
var framework=FrameworkSetup.GetSetFrameworkSettings();
image=cmsImageService.GetImage(Path.GetFileName(context.Request.PhysicalPath)、framework.EventId);
}
var contextType=“image/jpg”;
var format=ImageFormat.Jpeg;
开关(Path.GetExtension(context.Request.PhysicalPath.ToLower())
{
大小写“.gif”:
contextType=“image/gif”;
format=ImageFormat.Gif;
后藤违约;
大小写“.jpeg”:
案例“.jpg”:
contextType=“image/jpeg”;
格式=ImageFormat.Jpeg;
后藤违约;
案例“.png”:
contextType=“image/png”;
format=ImageFormat.Png;
后藤违约;
违约:
context.Cache.Insert(context.Request.PhysicalPath,image);
context.Response.ContentType=contextType;
context.Response.BinaryWrite(image);
context.Response.Flush();
打破
}

我不确定这是否完全回答了您的问题。。。我还构建了一个由HttpHandler驱动的ASP.NETCMS,它还允许物理.aspx页面。由于我只有少量的物理.aspx文件和位置,所以管理执行的最简单方法是通过web.config

首先,我将网站(一般而言)配置为使用我的处理程序-登录页面除外(作为示例):


你说得对,这不是一个完整的答案,但在某种程度上验证了我的尝试。
        byte[] image = null;
        if (File.Exists(context.Request.PhysicalPath))
        {
            FileStream fs = new FileStream(context.Request.PhysicalPath, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            image = br.ReadBytes((int)fs.Length);
        }
        else
        {
            IKernel kernel = new StandardKernel(new ServiceModule());
            var cmsImageService = kernel.Get<IContentManagementService>();
            var framework = FrameworkSetup.GetSetFrameworkSettings();
            image = cmsImageService.GetImage(Path.GetFileName(context.Request.PhysicalPath), framework.EventId);
        }

        var contextType = "image/jpg";
        var format = ImageFormat.Jpeg;

        switch (Path.GetExtension(context.Request.PhysicalPath).ToLower())
        {
            case ".gif":
                contextType = "image/gif";
                format = ImageFormat.Gif;
                goto default;
            case ".jpeg":
            case ".jpg":
                contextType = "image/jpeg";
                format = ImageFormat.Jpeg;
                goto default;
            case ".png":
                contextType = "image/png";
                format = ImageFormat.Png;
                goto default;
            default:
                context.Cache.Insert(context.Request.PhysicalPath, image);
                context.Response.ContentType = contextType;
                context.Response.BinaryWrite(image);
                context.Response.Flush();
                break;
        }
<add verb="*" path="login.aspx" type="System.Web.UI.PageHandlerFactory"/>
<add verb="*" path="Register.aspx" type="System.Web.UI.PageHandlerFactory"/>
<add verb="*" path="*.aspx" type="Morphfolia.PublishingSystem.HttpHandlers.DefaultHandler, Morphfolia.PublishingSystem"/>
<location path="Morphfolia/_publishing">
  <system.web>
    <httpHandlers>
      <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/>
    </httpHandlers>
  </system.web>
</location>