1:建立Handler.cs文件

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

/// <summary>
/// Handler 的摘要说明
/// </summary>
public class Handler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string key = context.Request.QueryString.ToString();
        string filename =MD5(Common.GetIp() + "123456);
        if (!key.Equals(filename))
        {           
            return;
        }
        else
        {
            context.Response.Expires = 0;
            context.Response.Clear();
            context.Response.ContentType = "audio/mpeg3";
            context.Response.WriteFile(context.Request.PhysicalPath);
            context.Response.End();
        }
    }   
    public bool IsReusable
    {
        get
        {
            return true;
        }
    }
}

2:播放音频的代码加入

string filename = MD5(Common.GetIp() + "123456");
 music = 路径 + "伤心泪 陈星.mp3?" + filename;

生成如下:

 <object class/>
    </object>

3:配置IIS,对IIS的asp.net处理内容进行过滤,对.mp3文件指定同aspx相同的dll

4:web.config中加入 

<httpHandlers>
      <add verb="*" path="*.mp3" type="Handler,App_Code"/>
</httpHandlers>

 

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-09-14
  • 2021-12-30
  • 2021-10-04
  • 2021-12-24
  • 2021-07-06
  • 2022-03-09
猜你喜欢
  • 2022-12-23
  • 2021-06-24
  • 2021-12-09
  • 2022-12-23
  • 2021-11-18
  • 2021-08-29
相关资源
相似解决方案