Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有路径的ASP.Net 4.0路由问题_C#_Webforms_Asp.net Routing - Fatal编程技术网

C# 带有路径的ASP.Net 4.0路由问题

C# 带有路径的ASP.Net 4.0路由问题,c#,webforms,asp.net-routing,C#,Webforms,Asp.net Routing,关于4.0版本中的asp.net webform路由,我正在努力解决两个问题 第一个问题是本地服务器上的路径相同的路径适用于其他项目并在本地服务器上创建路径问题 第二个问题是路由在实际的托管web服务器上不起作用 示例代码 Global.asx public static void RegisterRoutes(RouteCollection routes) { routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" }

关于4.0版本中的asp.net webform路由,我正在努力解决两个问题

第一个问题是本地服务器上的路径相同的路径适用于其他项目并在本地服务器上创建路径问题

第二个问题是路由在实际的托管web服务器上不起作用

示例代码

Global.asx

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
    routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.png(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.gif(/.*)?" });
    routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
    routes.Add(new System.Web.Routing.Route("{resource}.css/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));
    routes.Add(new System.Web.Routing.Route("{resource}.js/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));

    // Page will Generate error if route for home page is take out then 
    // http://www.kashmirsouq.com without any page or quesry string wont work.

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


    ////For 
    routes.MapPageRoute("ParentCat", "buysell/{CatID}/{Title}", "~/buy-sell-in-kashmir.aspx", false,
         new RouteValueDictionary {
                    { "CatID", "0" },
                    { "Title", "Product-Category-not-found" }},
         new RouteValueDictionary {   
                    { "CatID", "^[0-9a-fA-Z-]{36}$" }
                }); 
}
parentCategoryList.ascx和.cs文件代码

            <asp:Repeater ID="rptParentCategoryListing" runat="server">
                <ItemTemplate>
                    <li><a href='<%#getURLRouting(Eval("parentGUID"),Eval("CatName")) %>' title='<%#  Eval("CatLinkTitle")%>'>
                        <%#  Eval("CatName")%></a> </li>
                </ItemTemplate>
            </asp:Repeater>




protected string getURLRouting(object CatID, object CatTitle)
{
    string strTitle = CatTitle.ToString();

    #region Generate SEO Friendly URL based on Title
    //Trim Start and End Spaces.
    strTitle = strTitle.Trim();
    //Trim "-" Hyphen
    strTitle = strTitle.Trim('-');
    strTitle = strTitle.ToLower();
    char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();

    //Replace . with - hyphen
    strTitle = strTitle.Replace(".", "-");
    //Replace Special-Characters
    for (int i = 0; i < chars.Length; i++)
    {
        string strChar = chars.GetValue(i).ToString();
        if (strTitle.Contains(strChar))
        {
            strTitle = strTitle.Replace(strChar, string.Empty);
        }
    }
    //Replace all spaces with one "-" hyphen
    strTitle = strTitle.Replace(" ", "-");
    //Replace multiple "-" hyphen with single "-" hyphen.
    strTitle = strTitle.Replace("--", "-");
    strTitle = strTitle.Replace("---", "-");
    strTitle = strTitle.Replace("----", "-");
    strTitle = strTitle.Replace("-----", "-");
    strTitle = strTitle.Replace("----", "-");
    strTitle = strTitle.Replace("---", "-");
    strTitle = strTitle.Replace("--", "-");
    //Run the code again...
    //Trim Start and End Spaces.
    strTitle = strTitle.Trim();
    //Trim "-" Hyphen
    strTitle = strTitle.Trim('-');
    #endregion
    string url = null;
    try
    {
       // url = "~/news/" + NewsID + "/" + pageid + "/" + strTitle; // +"&pgName=" + PageName;
        url = "~/buysell/"+CatID + "/" + strTitle;
     //   return url;
    }
    catch (Exception ex)
    {
        Response.Redirect("Error");
    }
    return url;
}
protected void Page_Load(object sender, EventArgs e)
{
    if (string.IsNullOrEmpty(Request["CatID"]))
    {
        sPID = RouteData.Values["CatID"].ToString();
        bIsGUID = IsGuid(sPID, out PID);
        addCanonicalURL = false;
    }
    else
    {
        sPID = Helper.GetQueryStringValue("CatID").ToString(); ;
        bIsGUID = IsGuid(sPID, out PID);
        addCanonicalURL = true;
    }


  // Code to get details based on sPID ParentCategory GUID
}

输出

使用default.aspx页面上的Current UserControl为父类别生成以下链接

http://localhost:59030/TravelKashir-Souq/~/buysell/1ef4f9db-14d1-4ff0-be79-922ce903bff4/电子技术

在上面的示例链接中,当我在用户控制函数中使用path时,它添加了
~/

url=“~/buysell/”+CatID+“/”+strTitle

如果我使用路径作为

url=“buysell/”+CatID+“/”+strTitle然后将父类别更改链接到

http://localhost:59030/TravelKashir-Souq/buysell/1ef4f9db-14d1-4ff0-be79-922ce903bff4/电子技术

在default.aspx页面上,路由工作正常&当我单击它时,它进入页面在克什米尔买卖。aspx

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
    routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.png(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.gif(/.*)?" });
    routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
    routes.Add(new System.Web.Routing.Route("{resource}.css/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));
    routes.Add(new System.Web.Routing.Route("{resource}.js/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));

    // Page will Generate error if route for home page is take out then 
    // http://www.kashmirsouq.com without any page or quesry string wont work.

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


    ////For 
    routes.MapPageRoute("ParentCat", "buysell/{CatID}/{Title}", "~/buy-sell-in-kashmir.aspx", false,
         new RouteValueDictionary {
                    { "CatID", "0" },
                    { "Title", "Product-Category-not-found" }},
         new RouteValueDictionary {   
                    { "CatID", "^[0-9a-fA-Z-]{36}$" }
                }); 
}
http://localhost:59030/TravelKashir-Souq/buysell/1ef4f9db-14d1-4ff0-be79-922ce903bff4/buysell/1ef4f9db-14d1-4ff0-be79-922ce903bff4/电子技术

在上,我尝试了不同的路径,但仍然无法正常工作,当我在共享主机上上载代码时,它无法工作并生成错误

HTTP错误404.0-找不到
您正在查找的资源已被删除、名称已更改或暂时不可用。

我对这个问题感到失望,因为我可以使代码中提到的相同路径在其他项目中工作而没有任何问题

在这方面,我将不胜感激

网站与我们的路由和路由版本不工作


配置:本地主机和共享主机上的IIS 7.5/asp.net 4.0=server@Grumbler:未被注意到,这是第一个问题的罪魁祸首让我看看它是否适用于共享主机第一个问题已解决,但我仍然无法在共享主机上运行它我收到相同的错误页未找到是什么在您的情况下“共享托管”?托管提供
MochaHost