编程人生

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

    private string GetRedirect(string badRequest)
    {
        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"pages/(\d+)$", (System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase));
        System.Text.RegularExpressions.MatchCollection matches = regex.Matches(badRequest);
        if (matches.Count > 0)
        {
            string id = matches[0].Value.Replace("pages/", "");
            int aId;
            try
            {
                aId = Int32.Parse(id);
                return "http://localhost:1731/web/pages/room.aspx?id=" + id;
            }
            catch
            {

            }
        }
        return badRequest;
    }
    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        string originalUrl = Request.Url.ToString();
        string newUrl = GetRedirect(originalUrl);
        if (newUrl != originalUrl)
        {
            System.Uri myUri = new Uri(newUrl);
            Context.RewritePath(myUri.PathAndQuery);
        }

    }

posted on 2006-11-05 20:52  choice  阅读(1696)  评论(0编辑  收藏  举报