views:

23

answers:

0

I am trying to access the page object in module and change the hyper links urls. Page object is being access properly, but changes I am making are not effecting the output. I mean here I am changing the url to TestURL.aspx, but this is not comming. could anyone help me in this please?

namespace Dutt.PageURLBuilder
{
    class PageURLModule : IHttpModule
    {
        #region IHttpModule Members
        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            var handler = HttpContext.Current.Handler;
            if (handler != null && handler is Page)
            {
                SetHyperLinkNavigationURL(handler as Page);
            }            
        }

        private void SetHyperLinkNavigationURL(Control Page)
        {
            foreach (Control ctrl in Page.Controls)
            {
                if (ctrl is HyperLink)
                {
                    ((HyperLink)(ctrl)).NavigateUrl = "TestURL.aspx";
                }
                else
                {
                    if (ctrl.Controls.Count > 0)
                    {
                        SetHyperLinkNavigationURL(ctrl);
                    }
                }
            }
        }

        public void Dispose()
        {
        }
        #endregion
    }
}