How to secure access to SWF file using ASP.NET?

后端 未结 2 1908
礼貌的吻别
礼貌的吻别 2021-01-05 17:51

We have a swf file that we want to secure and make available only to authorized users.

I embedded the file in an aspx page and that works fine, since ASP.NET handles

2条回答
  •  生来不讨喜
    2021-01-05 18:07

    Aristos,

    You were right. Last afternoon just before I went home I tried creating a custom HTTP handler. And it worked nice. :-) Thanks for answering +1

    public class CustomFlashHandler : IHttpHandler
    {
    
    public void ProcessRequest(HttpContext context)
    {
      if (!context.User.Identity.IsAuthenticated)
      {
        context.Response.Redirect("Default.aspx?ReturnUrl=%2felVideo.aspx");
        context.Response.StatusCode = 401;
        return;
      }
    
      var url = context.Request.CurrentExecutionFilePath;
    
      if (string.IsNullOrEmpty(url)) return;
    
      HttpContext.Current.Response.ClearContent();
      HttpContext.Current.Response.ClearHeaders();
      HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("filename={0}", url));
      HttpContext.Current.Response.AddHeader("Content-Type", "application/x-shockwave-flash");
      HttpContext.Current.Response.WriteFile(url);
      HttpContext.Current.Response.End();
    }
    
    public bool IsReusable
    {
      get { return false; }
    }
    

    }

    Like Aristos said, you have to map ASP.NET to handle .swf files in IIS.

    alt text http://www.freeimagehosting.net/uploads/30424ac60a.png

    Then add the custom mapping in the application's web.config

    
      
    
    

    1: href=http://www.freeimagehosting.net/>http://www.freeimagehosting.net/uploads/30424ac60a.png

    1: a href=http://www.freeimagehosting.net/>http://www.freeimagehosting.net/uploads/30424ac60a.png border=0 alt="Free Image Hosting">

提交回复
热议问题