如何使用ASP.NET保护对SWF文件的访问?

Int*_*gue 6 asp.net security iis flash

我们有一个swf文件,我们想要保护并仅供授权用户使用.

我将文件嵌入到aspx页面中并且工作正常,因为ASP.NET处理aspx页面,我可以使用ASP.NET授权功能,并且在web.config中限制对roles ="AllowedUsers"的访问.

然而,智能用户仍然可以直接访问该文件,例如www.mysite/flash.swf.我们希望这种访问安全.

任何帮助将不胜感激!

谢谢!

Int*_*gue 5

Aristos的,

你是对的.在我回家之前的一个下午,我尝试创建一个自定义的HTTP处理程序.它工作得很好.:-)感谢您回答+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; }
}
Run Code Online (Sandbox Code Playgroud)

}

就像Aristos所说,你必须映射ASP.NET来处理IIS中的.swf文件.

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

然后在应用程序的web.config中添加自定义映射

<httpHandlers>
  <add verb="*" path="*.swf" type="XXXXX.Web.XXXXX.CustomFlashHandler" validate="false" />
</httpHandlers>
Run Code Online (Sandbox Code Playgroud)

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 ="免费图片托管">