程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> ASP.NET中實現訪問鏈接的靜態地址映射

ASP.NET中實現訪問鏈接的靜態地址映射

編輯:關於ASP.NET

protected void Application_BeginRequest(Object sender, EventArgs e) {

        string strCurrentPath;
        strCurrentPath = Request.Path;
        //make sure that it ends with aspx.  This is some quick validation on the path.
        //This will shortcut processing for images and other files (WebResource.axd, for example).
        if(System.IO.Path.GetExtension(strCurrentPath).EndsWith(
            "aspx", true, System.Globalization.CultureInfo.InvariantCulture)) {
            string strCustomPath;
            string qString = Request.QueryString.ToString();
            if(qString != string.Empty)
                qString = "&" + qString;
            strCurrentPath = strCurrentPath.ToLowerInvariant();
            string appRoot = GetAppRoot(strCurrentPath);
            //string pageName = "";
            // the URL contains this folder name
            //Response.Write(strCurrentPath);
            if(strCurrentPath.IndexOf("catalog/", StringComparison.InvariantCultureIgnoreCase) > -1) {

                appRoot = appRoot.Replace("catalog/", "");
                strCustomPath = appRoot + "catalog.aspx?guid=" + System.IO.Path.GetFileNameWithoutExtension(strCurrentPath) + qString;

                // rewrite the URL
                Context.RewritePath(strCustomPath, false);
            }
            else if(strCurrentPath.IndexOf("product/", StringComparison.InvariantCultureIgnoreCase) > -1) {
                appRoot = appRoot.Replace("product/", "");

                strCustomPath = appRoot + "product.aspx?guid=" + System.IO.Path.GetFileNameWithoutExtension(strCurrentPath);
                // rewrite the URL

                Context.RewritePath(strCustomPath, false);
            }
        }
    }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved