Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static string RegisterRoutes(string routes)
{
    string MainUrl = routes;
    string Url = null;
    string[] Urllast = null;
    string RouteUrl = null;
    try
    {
        if (routes.Contains("FinalRequestCompilation.aspx"))
        {
            RouteTable.Routes.Clear();
            Urllast = MainUrl.Split('/');
            Url = MainUrl.Split('/').Last();
            RouteUrl = Url.Split('.').First();
            RouteTable.Routes.MapPageRoute(RouteUrl, Urllast[6] + "/" + RouteUrl, "~/"+Urllast[6] + "/" + Url);
            return RouteUrl;
        }
        else
        {
            return routes;
        }
    }
    catch (Exception ex)
    {
        return null;
    }
}

but after redirecting to particular route it gives 404 on IIS

here is my redirection:
C#
protected void CMen_MenuItemClick(object sender, MenuEventArgs e)
{
    try
    {
        objMenuBal = new MenuBal();

        DataTable dt = new DataTable();
        if (e.Item.Value != "")
        {

            string code = e.Item.Value;
            string ServerIp = Request.Url.GetLeftPart(UriPartial.Authority) + "/";
            //DataSet ds = objMenuBal.GetHomeLink(code, "S", ref Err);
            DataSet ds = objMenuBal.GetHomeLink_Test(code, "S", ServerIp, ref Err);

            if (Err != "")
            {
                lblErrormsg.Text = Err;
                return;
            }
            else
            {
                string url = ds.Tables[0].Rows[0][0].ToString();
                // url = "~"+url.Substring(34, url.Length-34);

                objsession["SubModName"] = e.Item.Text;
                objsession["FormIDCode"] = e.Item.Value;
                objUserLogin.FormCode = e.Item.Value;
                string Form_Name = e.Item.Text;
                objUserLogin.FormName = Form_Name.Replace('>',' ');
                Session["Event"] = "";
                objsession["PageName"] = url;
                Session["objUserLogin"] = objUserLogin;
                DataSet dtSystemActivation = objMenuBal.GetSystemActivation(code, "A", ref Err);
                if (Err != "")
                {
                    lblErrormsg.Text = Err;
                    return;
                }
                else
                {
                    if (dtSystemActivation.Tables[0].Rows[0][0].ToString() == "")
                    {
                       insertInSession_Log(); //  /*keep session log of each link visit.*/

                        if(ddlParentMenu.SelectedItem.Text=="Master")
                        {
                            if (objsession["SubModName"].ToString() == "> Distribution Group")
                            {
                                //Response.Redirect(url);  
                                if (url.Contains("FinalRequestCompilation.aspx"))
                                {
                                    Response.RedirectToRoute(UrlRoute.RegisterRoutes(url));
                                }
                                else
                                { Response.Redirect(url); }
                            }
                            if (objsession["SubModName"].ToString() == "> Company Specialist Mapping")
                            {
                                //Response.Redirect(url);
                                if (url.Contains("FinalRequestCompilation.aspx"))
                                {
                                    Response.RedirectToRoute(UrlRoute.RegisterRoutes(url));
                                }
                                else
                                { Response.Redirect(url); }   
                            }
                            else
                            {
                                Response.Redirect("~/CommonSearch/CommonSearch.aspx");
                            }
                        }
                        else
                        {                                   
                               // Response.Redirect(url);
                            if (url.Contains("FinalRequestCompilation.aspx"))
                            {
                                Response.RedirectToRoute(UrlRoute.RegisterRoutes(url));
                            }
                            else
                            { Response.Redirect(url); } 
                        }
                    }
                    else
                    {
                        ClientScriptManager CSM = Page.ClientScript;
                        string strconfirm = "<script>alert('This functionality of EP has been temporarily deactivated. Contact Your Local Bits for more information.')</script>";
                        CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        lblErrormsg.Text = ex.Message.ToString();
    }

pls help me out..
Posted
Updated 5-Jan-16 2:26am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900