路线集合中找不到路线

时间:2017-10-11 12:00:22

标签: asp.net routes

我已经建立了一个ASP .NET网店,所有这些都在本地运行中运行良好。我上传它,首先它工作正常但是大约1小时后出现Server Error in '/' Application

完整文本位于添加的文件中。提到ProductsByCategoryRoute的两个地方是:

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        // Initialize the Product database.
        Database.SetInitializer(new ProductDatabaseInitializer());

        // Create the custom role and user.
        RoleActions roleActions = new RoleActions();
        roleActions.AddUserAndRole();

        // Add Routes.
        RegisterCustomRoutes(RouteTable.Routes);
    }

    void RegisterCustomRoutes(RouteCollection routes)
    {
        routes.MapPageRoute(
            "ProductsByCategoryRoute",
            "Category/{CategoryName}",
            "~/ProductList.aspx"
        );
        routes.MapPageRoute(
            "ProductByNameRoute",
            "Product/{ProductName}",
            "~/ProductDetails.aspx"
        );
    }
}

  

<div id="CategoryMenu" style="text-align: center">       
    <asp:ListView ID="CategoryList"  
        ItemType="MyArtShop.Models.Category" 
        runat="server"
        SelectMethod="GetCategories" >
        <ItemTemplate>
            <b style="font-size: large; font-style: normal">
                <a href="<%#: GetRouteUrl("ProductsByCategoryRoute", new {CategoryName = Item.CategoryName}) %>">
                  <%#: Item.CategoryName %>
                </a>
            </b>
        </ItemTemplate>
        <ItemSeparatorTemplate>  |  </ItemSeparatorTemplate>
    </asp:ListView>
</div>​

我尝试了一切似乎没有任何帮助的事情。

Server Error in '/' Application.
________________________________________
A route named 'ProductsByCategoryRoute' could not be found in the route collection.
Parameter name: name
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: A route named 'ProductsByCategoryRoute' could not be found in the route collection.
Parameter name: name

Source Error: 

Line 98:                 <ItemTemplate>
Line 99:                     <b style="font-size: large; font-style: normal">
Line 100:                    <a href="<%#: GetRouteUrl("ProductsByCategoryRoute", new {categoryName = Item.CategoryName}) %>">
Line 101:                        <%#: Item.CategoryName %>
Line 102:                    </a>

Source File: \\hosting.local\hosting\IIS\IISData\alefever.be\wwwroot\Site.Master    Line: 100 

Stack Trace: 

[ArgumentException: A route named 'ProductsByCategoryRoute' could not be found in the route collection.
Parameter name: name]
   System.Web.Routing.RouteCollection.GetVirtualPath(RequestContext requestContext, String name, RouteValueDictionary values) +3212645
   System.Web.UI.Control.GetRouteUrl(String routeName, RouteValueDictionary routeParameters) +61
   System.Web.UI.Control.GetRouteUrl(String routeName, Object routeParameters) +41
   ASP.site_master.__DataBind__control39(Object sender, EventArgs e) in \\hosting.local\hosting\IIS\IISData\alefever.be\wwwroot\Site.Master:100
   System.Web.UI.Control.OnDataBinding(EventArgs e) +84
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +150
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.Control.DataBindChildren() +185
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +160
   System.Web.UI.Control.DataBind() +17
   System.Web.UI.WebControls.ListView.CreateItemsWithoutGroups(ListViewPagedDataSource dataSource, Boolean dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) +797
   System.Web.UI.WebControls.ListView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +1030
   System.Web.UI.WebControls.ListView.PerformDataBinding(IEnumerable data) +35
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +34
   System.Web.UI.WebControls.ModelDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +80
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.ListView.PerformSelect() +102
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   System.Web.UI.WebControls.ListView.CreateChildControls +52
   System.Web.UI.Control.EnsureChildControls() +92
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +985

0 个答案:

没有答案