开发者

Problem with routing and WebSite in Classic .NET AppPool

开发者 https://www.devze.com 2023-02-01 05:18 出处:网络
I\'m using Url Routing (System.Web.Routing) on a website with framework 3.5 and IIS running on the Classic.NET AppPool. My web.config is like this:

I'm using Url Routing (System.Web.Routing) on a website with framework 3.5 and IIS running on the Classic.NET AppPool. My web.config is like this:

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

My global.asax is like this:

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

And so is my 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;
    }
}

When I access the address localhost/WebSiteTesteRoteamento/, the site loads.开发者_运维技巧 But when I access the address localhost/WebSiteTesteRoteamento/bikes/sale or localhost/WebSiteTesteRoteamento/teste appears the error 404. Somebody help me?


I think that 3.5 System.Web.Routing just doesn't work at all in Classic .NET AppPool. What is the reason you have to use Classic .NET AppPool?

If you have to use Classic .NET AppPool you might try using IIS URL Rewrite 2.

0

精彩评论

暂无评论...
验证码 换一张
取 消