1

url.for を使用して .css ファイルや .js ファイルなどの静的ファイルを Web サイトからダウンロードするようにユーザーを制限する必要があるという問題があります。 .js ファイルのリクエストは正常にブロックされていますが、それに伴い、私の Web サイトでその .js ファイルの使用が許可されていません。それを行う方法はありますか?

4

1 に答える 1

0

Http モジュールを使用して、URL にこれらの特定の拡張子が含まれているかどうかを確認できます。たとえば、App_code フォルダーに http モジュールを作成し、web.config で http モジュールを構成します。

namespace HttpUrlRewrite
{
    /// <summary>
    /// Summary description for HttpUrlRewrite
    /// </summary>
    public class Rewriter  : System.Web.IHttpModule
    {


        public void Init(System.Web.HttpApplication Appl)
        {
            Appl.BeginRequest += new System.EventHandler(Rewrite_BeginRequest);
        }


        public void Dispose()
        {
        }


        public void Rewrite_BeginRequest(object sender, System.EventArgs args)
        {
            System.Web.HttpApplication App = (System.Web.HttpApplication)sender;
            string path = App.Request.Path;


            string strExt = System.IO.Path.GetExtension(path);
            if (strExt == ".css")
            {
                //Do Something
                HttpContext.Current.Response.Redirect("error.aspx");
            }
            else
            {
                //Do Something
            }


        }
    }
}

                <httpModules>
                        <add type="HttpUrlRewrite.Rewriter" name="HttpUrlRewrite" />
                </httpModules>
于 2012-06-21T14:45:27.127 に答える