Click here to Skip to main content
15,883,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used to do when the routing server. I have a problem.
No problem if http://myweb.com/news/22.aspx
But
If http://myweb.com/news/22 problem: 404 - File or directory not found.

id do this :

global.asax

C#
void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
         routes.Add("News", new Route("News/{ID}",new CustomRouteHandler("~/News/News.aspx")));
    }


CustomRouteHandler.cs class :
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Routing;
using System.Web.Compilation;

public class CustomRouteHandler : IRouteHandler
{
    public CustomRouteHandler(string virtualPath)
    {
        this.VirtualPath = virtualPath;
    }

    public CustomRouteHandler()
    {
    }

    public string VirtualPath { get; private set; }

    public IHttpHandler GetHttpHandler(RequestContext
          requestContext)
    {
        var page = BuildManager.CreateInstanceFromVirtualPath
             (VirtualPath, typeof(Page)) as IHttpHandler;
        return page;
    }
}


web.config :
C#
<add assembly="System.Web.Routing, Version=3.5.0.0,Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

C#
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,System.Web.Routing, Version=3.5.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />

C#
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler,System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />


link :

ASP.NET
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/news/22" Text="News"></asp:HyperLink>




in local no problem , but server error
Even when .Html or .jsp I use
What is the problem?
Posted

1 solution

Can you confirm if asp.net MVC is installed on the server.
 
Share this answer
 

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