公司更名了,换了logo。所以原来的logo和公司名称都要换掉。但是有个需求,对以前的老客户,又不想换。所以需要根据登录的用户,动态的显示不同的图片和公司名称。以前的图片名和公司名称都是些死在各个页面的html里面的。如果一个一个的去改,加到资源文件里面,或者用代码动态的获得图片公司名称,都需要大量的改动所有相关页面的代码。所以想问问大家,有没有什么好办法,比如是不是可以在页面产生HTML呈现到用户浏览器以前,过滤相应的图片名称和公司名称,从而实现动态的效果?也就是说,在所有的页面呈现以前,加一个过滤功能,不知道是不是可行,有没有兄弟做过类似的解决方案,能否提供一下实现。谢了

解决方案 »

  1.   

    这个问题很easy啦,你可以在httpmodule的时候,在httpfilter里面去做,根据权限判断,应该把以前的logo替换成新的logo,还是继续用老的logo
      

  2.   

    死在HTML 页面里的就没办法了 除非 有对IIS 或者 web 服务请求的处理的功能 否则就不行PS: 可以搞一个小程序 替换所有的HTML 页面 吧原来的图标那些 替换为动态的js显示的方式 
      

  3.   

    就是 重新生成 html 文件
      

  4.   

    怀疑,这是.NET的么。怎么会都是HTML的。
    没有应用到母版页么。
      

  5.   

    楼主,实在想不起来就用笨方法,把logo存入数据库,当用户登陆根所权限动态更换logo,就是有点慢。。
      

  6.   

    利用HttpModule和Response.Filter来实现这个功能,既然是用HttpModule,那当然就得弄个实现了IHttpModule的类了:using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using System.Web; namespace K2046.Handlers
    {
     public class FilterModule : IHttpModule
     {
     public void Dispose()
     {
     // Do Nothing.
     } public void Init(HttpApplication context)
     {
     context.BeginRequest += new EventHandler(Application_BeginRequest); 
     } void Application_BeginRequest(object sender, EventArgs e)
     {
     HttpApplication app = sender as HttpApplication; 
     if (true)//这里看情况加上你的条件,要不然所有的请求都会被处理,会造成其它文件类型的输出异常.
     {
     app.Response.Filter = new ResponseFilter(app.Response.Filter); 
     }
     }
     #endregion
     }
    } web.Config的<system.web>中再加上如下代码:<httpModules>
     <add name="ResponseFilter" type="K2046.Handlers.FilterModule, K2046.Handlers"/>
     </httpModules>esponseFilter的类,这个也是自己实现的,代码如下:using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using System.IO; 
    using System.Text.RegularExpressions; namespace K2046.Handlers
    {
     public class ResponseFilter : Stream
     {
     private Stream _StreamFilter;  private ResponseFilter() { } public ResponseFilter(Stream stream)
     {
     _StreamFilter = stream; 
     } public override bool CanRead
     {
     get { return true; }
     } public override bool CanSeek
     {
     get { return true; }
     } public override bool CanWrite
     {
     get { return true; }
     } public override void Flush()
     {
     _StreamFilter.Flush(); 
     } public override long Length
     {
     get
     {
     return _StreamFilter.Length; 
     }
     } public override long Position
     {
     get
     {
     return _StreamFilter.Position; 
     }
     set
     {
     _StreamFilter.Position = value; 
     }
     } public override int Read(byte[] buffer, int offset, int count)
     {
     return _StreamFilter.Read(buffer, offset, count); 
     } public override long Seek(long offset, SeekOrigin origin)
     {
     return _StreamFilter.Seek(offset, origin); 
     } public override void SetLength(long value)
     {
     _StreamFilter.SetLength(value); 
     } public override void Write(byte[] buffer, int offset, int count)
     {
     string Html = Encoding.UTF8.GetString(buffer); 
    //你可以在这里干活了,做判断,然后判断是显示哪个logo
    if(判断如果应该输入新的LOGO
     //Html = Regex.Replace(Html, @">\s+?<", "><"); 
    Html=Html.Replace("olologo.gif","newlogo.gif");
     buffer = Encoding.UTF8.GetBytes(Html); 
     _StreamFilter.Write(buffer, offset, buffer.Length); 
     }
     }
    }
      

  7.   

    说真的,楼主的logo 不是在CSS里定义的吗,可以试试,不用用户加载不同CSS
      

  8.   

    另外如果有html之类静态页,你也可以配置webconfig,让他走httpmodule这个模块,去过滤相关的logo,这样就整个OK了
      

  9.   

    同意17楼哥们所说.
    用户登陆后转不同的页面就行了.但登陆的页面LOGO你怎么用?
      

  10.   

    那要改几千个网页的代码,比如原来是href = "/123.jpg" 现在都需要改成 href = "<%....jpg%>"
      

  11.   

    还没遇到过这样需求,公司换了个logo就不是以前的公司了?
    呵呵,我明白这个也由不得我们,看了楼上的回答,我觉得自定义HTTP管道的那个方法应该可行
      

  12.   

    区分新老客户不是问题,只要用户登录,我们就能找到他是不是老客户,然后存到session里就可以了。
      

  13.   

    你的logo 使用img 显示的吧。把img 的src保存在数据库里。然后根据不同用户,绑定不同的src就行了
      

  14.   

    给你一个方案吧。新建一个站点。即提供给新用户的站点。里面都使用最新的页面LOGO等。做一个 REWRITE 当地址过来时先统一跳转到一个处理页面。最后通过REWRITE重写,将判断出是新用户的跳到新站点,老用户的跳到老站点。数据库共用也就不存在数据问题了。
      

  15.   

    18楼的方法很合适,利用HttpHandler在页面加载前拦截到要显示的logo图片,然后判断是否新客户开改变logo图片的连接地址就可以了,非常简单的问题。
      

  16.   

    18楼用的HttpModel,也可以使用HttpHandler
    public class ImageHandler : IHttpHandler
        {
            public bool IsReusable
            {
                get { return true; }
            }        public void ProcessRequest(HttpContext context)
            {
                处理代码
            }
         }
    然后在web.config中加配置
    <httpHandlers>
          <add path="logo.gif(图片名称)" verb="*" type="(有命名空间就加上)ImageHandler"></add>
      

  17.   

    HttpHandler 换图的做法我有寫过,提供您参考: 
    ASP.NET 案例分享:因应多站台透过 IHttpHandler 动态切换图片水印 
    判断逻辑像你所说要改用 Session,所以这一篇也可以参考一下:
    HttpHandler 中使用 Session 的注意事项其實个人觉得棘手的是公司名称的部分...
      

  18.   

    HttpHandler就是解决此类问题呀,楼上的说的我都晕了
      

  19.   

    你的logo 使用img 显示的吧。 把img 的src保存在数据库里。然后根据不同用户,绑定不同的src就行了
      

  20.   

    写个windows service,重新生成下html页面,判断如果是 老客户 Logo就替换为 logo.jpg,如果是新客户就替换为new_logo.jpg
      

  21.   

    用Handlerusing System;
    using System.Collections.Generic;
    using System.Web;/// <summary>
    ///PicHandler 的摘要说明
    /// </summary>
    namespace CustomerHandler
    {
        public class PicHandler:IHttpHandler
        {
            public void ProcessRequest(HttpContext context)
            {
                string FileName = context.Server.MapPath(context.Request.FilePath);
                context.Response.ContentType = "image/JPEG";
                if (context.Request.Cookies["XX"].ToString() == "old")
                {
                    context.Response.WriteFile(FileName);
                }
                else
                {
                    context.Response.WriteFile("newlogo.jpg");
                }
            }        public bool IsReusable
            {
                get { return true; }
            }
        }
    }<httpHandlers>
    <add path="oldlogo.jpg" verb="*" type="CustomerHandler.PicHandler,PicHandler"/>
    </httpHandlers>刚学,看行不行。
      

  22.   

    对,这和放图片盗链是一个道理不?在HttpHandler判断
      

  23.   

    根据用户和模板生成HTML页面
    页面过滤可使用HttpHandler