Classic .NET AppPool中的路由和WebSite问题

时间:2010-12-28 13:28:28

标签: c# .net asp.net

我在使用Classic.NET AppPool上运行的框架3.5和IIS的网站上使用Url Routing(System.Web.Routing)。我的web.config是这样的:

<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
< /assemblies>

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

我的global.asax是这样的:

protected void Application_Start(object sender, EventArgs e)
{
    Debugger.Break();
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Add("BikeSaleRoute", new Route
    (
       "bikes/sale",
       new CustomRouteHandler("~/Contoso/Products/Details.aspx")
    ));
    routes.Add("Teste", new Route("teste", new CustomRouteHandler("~/Teste.aspx")));
}

我的CustomRouteHandler也是如此:

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

    public string VirtualPath { get; private set; }

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        HttpContext.Current.RewritePath(String.Format("{0}", VirtualPath));
        var page = BuildManager.CreateInstanceFromVirtualPath
             (VirtualPath, typeof(Page)) as IHttpHandler;
        return page;
    }
}

当我访问地址localhost / WebSiteTesteRoteamento /时,网站会加载。但是当我访问地址localhost / WebSiteTesteRoteamento / bikes / sale或localhost / WebSiteTesteRoteamento / teste时出现错误404.有人帮助我吗?

1 个答案:

答案 0 :(得分:0)

我认为3.5 System.Web.Routing在Classic .NET AppPool中根本不起作用。你必须使用Classic .NET AppPool的原因是什么?

如果您必须使用Classic .NET AppPool,可以尝试使用IIS URL Rewrite 2