ASP.NET 3.5路由不处理/(根URL) [英] ASP.NET 3.5 Routing Not Handling / (Root URL)

查看:267
本文介绍了ASP.NET 3.5路由不处理/(根URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET 3.5中新的路由功能来充当我的包罗了所有的页面请求到我的网站。我已经注册我的路线在Global.asax内有:

I'm using the new routing functionality in ASP.NET 3.5 to act as my catch-all for page requests to my website. I've registered my route as follows within the global.asax,

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {

        RegisterRoutes(RouteTable.Routes);

    }

    private void RegisterRoutes(RouteCollection Routes)
    {

        Route r = new Route("{*URL}", new MyRouteHandler());
        Routes.Add(r);

    }

</script>

在code工作绝对罚款除/(根页)的所有URL。如果我去其他任何URL /胡说/事/富/它工作正常,预期我的处理程序运行。

The code works absolutely fine for all URLs except / (the root page). If I go to any other URL /blah/something/foo/ it works fine and my handler is run as expected.

我怎样才能得到它超过根页上运行?我通过运行Visual Studio 2008中的生成的code Web服务器。

How can I get it to run over the root page? I am running the code via Visual Studio 2008's build in web server.

推荐答案

卡西尼(Visual Studio的内置的Web服务器)可能与路由问题。

Cassini (Visual Studio's built-in webserver) may have a problem with routing.

要从<报价href=\"http://blogs.msdn.com/dmitryr/archive/2009/04/23/cassini-support-for-friendly-urls-routing.aspx\"相对=nofollow> Dmitryr的博客:

卡西尼曾用路由ASP.NET项目一个问题,因为目录列表功能。卡西尼号将与上市为一个目录的任何请求响应目录,而不移交请求到ASP.NET。其结果是,对友好的URL请求将被卡西尼得到截获并不会到达ASP.NET。

Cassini had a problem with ASP.NET projects using Routing due to the directory listing feature. Cassini would respond with the directory listing to any request for a directory, without handing over the request to ASP.NET. As a result, requests for friendly URLs would get intercepted by Cassini and never reach ASP.NET.

此更新(v3.5.0.1)改变周围的逻辑 - 所有的请求到ASP.NET,再卡西尼404拦截和响应,如果请求是一个目录,它与目录列表响应。应用程序依靠友好的URL /路由现在卡西尼更好。

This update (v3.5.0.1) changes the logic around – all requests go to ASP.NET first, then Cassini intercepts 404 responses and, if the request was for a directory, it responds with the directory listing. Applications relying on friendly URLs / Routing now work better with Cassini.

您已经没有提到你所看到的行为,当你去根。如果你没有得到一个目录列表,也许你需要删除默认的页面?

You've not mentioned what behavior you see when you go to the root. If you're not getting a directory listing, perhaps you need to remove your default page?

这篇关于ASP.NET 3.5路由不处理/(根URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆