Friday, February 18, 2011

Dynamically Renaming or re-writing ASPX page name in asp.net

1. Add global.asax file and include this code
here i will rename MP4B.aspx and will put logo and content of page dynamically
 void Application_BeginRequest(object sender, EventArgs e)
    {
        string fullOrigionalpath = Request.Url.ToString();
        if (fullOrigionalpath.Contains("/Mobile4Business/"))
        {
            Context.RewritePath("/Mobile4Business/MP4B.aspx");
        }
       
    } 

 private string GetPageName(string url)
    {
        int startIndex = url.LastIndexOf('/');
        startIndex = startIndex + 1;
        int endindex = url.LastIndexOf('?');
        if (endindex == -1)
        { endindex = url.Length;
        }
        return url.Substring(startIndex, (endindex - startIndex));
    }

2.  write code in code behind ....Here you can use your own code for binding page
 protected void Page_Load(object sender, EventArgs e)
    {
      
      if(!IsPostBack)
     {
            string fullOrigionalpath = Request.RawUrl.ToString();
            string rawURL = GetPageName(fullOrigionalpath);
            string[] RID = rawURL.Split('.');
             Session["RID"] = Convert.ToString( Convert.ToInt32(RID[0]));
            fillpageinfo();
        
      }
    }
    private void fillpageinfo()
    {
       
           SqlDataReader dr;
           dr = objReseller.GetRsellerDetails();
           if(dr.HasRows)
            {
                dr.Read();
                HtmlImage RLogo1 = (HtmlImage)this.Page.FindControl("RLogo");
                RLogo1.Src = "..\\images\\" + dr["LogoFileName"].ToString();
                ResellerPageText.InnerHtml = dr["PageContent"].ToString();
          
            }
     
      
    }

 private string GetPageName(string url)
    {
        int startIndex = url.LastIndexOf('/');
        startIndex = startIndex + 1;
        int endindex = url.LastIndexOf('?');
        if (endindex == -1)
        {
            endindex = url.Length;
        }
        return url.Substring(startIndex, (endindex - startIndex));
    }

No comments:

Post a Comment