Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello

why this cod is not working?

C#
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {

        this.routingData(RouteTable.Routes);

    }

    void routingData(RouteCollection routes)
    {

        int num = Convert.ToInt32 (HttpContext.Current.Application["num"]);
        string name = string.Empty;
        for (int i = 0; i < num; i++)
        {
            name += "{Name" + i + "}" ;
        }

        routes.MapPageRoute("ITEMs", name , "~/Default.aspx");

        routes.MapPageRoute("ITEMsssss", "cat/{NAME}" + name, "~/ITEM.aspx");

        
                
        
        
        
    }
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>


[Edit]

C#
my behind code is : 

 protected void Button1_Click(object sender, EventArgs e)
    {
        //Application["numCat"] = 2;
        //object category = "mohammad/reza";
        //Page.RouteData.Values["id"] = 1;
        //Response.Redirect("category/"+category + "/item/" + 1 + "-ALIAsS");
        string url = "sfsdfs/sdfsfs/sdfsfs/sdfsf/";
        string[] splits  = Regex.Split(url,"/");
        Application["num"] = splits.Length.ToString();
        string Url = Page.GetRouteUrl("ITEMs", new { NAME = "MOHAMMAD" });
        Response.Redirect(url);

    }


when i click on my button should split my URL and get number . then set application["num"] = number of split;

then in global URL routing map create .

don't create a name in my global for URL routing

[/Edit]
Posted
Updated 14-Jul-13 5:31am
v2
Comments
[no name] 14-Jul-13 10:42am    
And how would you think that we would know what "not working" means?
OriginalGriff 14-Jul-13 10:50am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
We don't know what you expect the code to do, so we can't help you based on that little information.
What is the code doing that it shouldn't, or not doing that it should?
Use the "Improve question" widget to edit your question and provide better information.
Joezer BH 14-Jul-13 11:06am    
This is hardly a descriptive title.

In future questions try to explain the main issue in a few simple words in the title, that is what it's for. Also - try to write down the nature of the problem, what exactly is not working, what you expect it to do etc.

Good luck,
Edo
tree1371 14-Jul-13 11:07am    
my behind code is :

protected void Button1_Click(object sender, EventArgs e)
{
//Application["numCat"] = 2;
//object category = "mohammad/reza";
//Page.RouteData.Values["id"] = 1;
//Response.Redirect("category/"+category + "/item/" + 1 + "-ALIAsS");
string url = "sfsdfs/sdfsfs/sdfsfs/sdfsf/";
string[] splits = Regex.Split(url,"/");
Application["num"] = splits.Length.ToString();
string Url = Page.GetRouteUrl("ITEMs", new { NAME = "MOHAMMAD" });
Response.Redirect(url);

}

when i click on my button should split my URL and get number . then set application["num"] = number of split;

then in global URL routing map create .

don't create a name in my global for URL routing

1 solution

Regex.Split takes 2 strings, an input and a pattern. You are trying to use Regex.Split like its String.Split. Basically your Regex is invalid, probably throwing an exception, and then the parts underneath are not being run.

Instead of using Regex.Split, use String.Split, like:

C#
string url = "sfsdfs/sdfsfs/sdfsfs/sdfsf/";
string[] splits  = url.Split('/');
Application["num"] = splits.Length.ToString();
string Url = Page.GetRouteUrl("ITEMs", new { NAME = "MOHAMMAD" });
Response.Redirect(url);
 
Share this answer
 

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

  Print Answers RSS


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