2010-04-06 81 views
6

我们有一个swf文件,我们想要保护并只提供给授权用户。如何使用ASP.NET来保护对SWF文件的访问?

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

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

任何帮助将不胜感激!

谢谢!

回答

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; } 
} 

}

像Aristos的说,你必须映射ASP.NET处理SWF文件的IIS。

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

然后加入在应用程序的web.config

<httpHandlers> 
    <add verb="*" path="*.swf" type="XXXXX.Web.XXXXX.CustomFlashHandler" validate="false" /> 
</httpHandlers> 

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

+0

感谢您分享代码+1。:) – Aristos 2010-04-11 16:08:06

1

我认为最简单快速的解决方案是将这个扩展(.swf)映射到asp.net处理。

我不知道它的作品,因为我没有这样做,但你可以试试看。

的另一种方式是把这个文件,隐藏的地方,或者用复杂的名字,并使用.ashx的文件只是阅读和发送它们。在.ashx文件中,您需要为闪存设置正确的Response.ContentType,并且只需读取并发送正确的文件