为什么我的代码不起作用? [英] why my code is not working?

查看:134
本文介绍了为什么我的代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



为什么这个鳕鱼不工作?



 <%@    应用   语言  =  C#   %>  
<%@ 导入 命名空间 = System.Web。路由 %>

< script runat = server >

void Application_Start( object sender,EventArgs e)
{

this .routingData(RouteTable.Routes);

}

void routingData(RouteCollection路线)
{

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)
{
// 在应用程序关闭时运行的代码

}

void Application_Error(< span class =code-keyword> object
sender,EventArgs e)
{
// 发生未处理错误时运行的代码

}

void Session_Start( object sender,EventArgs e)
{
// 新会话启动时运行的代码

}

void Session_End( object sender,EventArgs e)
{
/ / 会话结束时运行的代码。
// 注意:仅当sessionstate模式时才会引发Session_End事件
// 在Web.config文件中设置为InProc。如果会话模式设置为StateServer
// 或SQLServer,则不会引发该事件。

}

< / script >









我的代码 

protected void Button1_Click( object sender,EventArgs e)
{
// 应用[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, /);
应用程序[ num] = splits.Length.ToString();
string Url = Page.GetRouteUrl( ITEM new {NAME = MOHAMMAD});
Response.Redirect(url);

}





当我点击我的按钮时,我应该拆分我的网址并获取电话号码。然后设置应用程序[num] =拆分数量;



然后在全局URL路由映射中创建。



不在我的全局URL路由中创建名称



[/ Edit]

解决方案

< blockquote> Regex.Split需要2个字符串,一个输入和一个模式。您正在尝试使用Regex.Split,就像它的String.Split一样。基本上你的正则表达式是无效的,可能抛出异常,然后下面的部分没有运行。



而不是使用Regex.Split,使用String.Split,如:



  string  url =   sfsdfs / sdfsfs / sdfsfs / sdfsf /; 
string [] splits = url.Split(' / );
应用程序[ num] = splits.Length.ToString();
string Url = Page.GetRouteUrl( ITEM new {NAME = MOHAMMAD});
Response.Redirect(url);


hello

why this cod is not working?

<%@ 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]

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]

解决方案

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:

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);


这篇关于为什么我的代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆