Click here to Skip to main content
12,294,775 members (58,148 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0
when i tried for the url freindly only url is freindly but page is not loading.my code files are below

Global.asax.cs
public class Global : System.Web.HttpApplication
   {
 

       protected void Application_Start(object sender, EventArgs e)
       {
            RouteTable.Routes.MapPageRoute("StoreRoute",
            "{Name}",
            "~/index1.aspx");
       }
 
       protected void Session_Start(object sender, EventArgs e)
       {
 
       }
 
       protected void Application_BeginRequest(object sender, EventArgs e)
       {
           string mTemp;
           string murl;
           try
           {
               string initialurl = Request.Url.ToString();
 
               mTemp = initialurl.Substring(1, initialurl.LastIndexOf(".")-1);
               //murl = mTemp.Substring(1, mTemp.LastIndexOf(".aspx"));
               Context.RewritePath(mTemp);
            
           }
           catch (Exception ex)
           {
               ex.Message.ToString();
               
           }
       }
 
       protected void Application_AuthenticateRequest(object sender, EventArgs e)
       {
       }
 
       protected void Application_Error(object sender, EventArgs e)
       {
       }
 
       protected void Session_End(object sender, EventArgs e)
       {
       }
 
       protected void Application_End(object sender, EventArgs e)
       {
       }
   }
 
index1.cs
 
 public partial class index1 : System.Web.UI.Page
    {
        static string var = null;
        string getLoc = null;
        string strURL;//this line for url freindly 
        protected void Page_Load(object sender, EventArgs e)
        {
            string name = Page.RouteData.Values["Name"] as string;
            if (!IsPostBack)
            {
                halim();
                
            }
 
        }
 
        protected void halim()
        {
        HttpContext context = Context;
        string strURL, strURL1;
        string name = Page.RouteData.Values["Name"] as string;
        if (name != null)
        {
          if (name == "Aboutus")
            {
                strURL = "/Aboutus.aspx";
                HttpContext.Current.RewritePath("~" + strURL);//Substring(0, mTemp.LastIndexOf(".aspx")));
                
            }
            else if (name == "contactus")
            {
                strURL = "/contactus.aspx";
                Response.Redirect(strURL);
                HttpContext.Current.RewritePath("~" + strURL);
            }
        }
       }
Posted 21-Dec-12 0:25am
Edited 21-Dec-12 0:32am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It looks like you have your code in the wrong sections..


Maybe this LINK will help you..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160525.2 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100