站点根目录或主页的 Web.Routing

发布于 2024-08-28 04:03:05 字数 626 浏览 2 评论 0原文

我正在使用 Web.Routing 进行一些工作,使用它来为站点提供友好的 url 和类似 Rest 的界面,该站点本质上是由单个 IHttpHandler 呈现的。没有 Web 表单,处理程序生成所有 html/json 并将其写入流程请求的一部分。

例如,这对于 /Sites/Accounting 等内容非常有效,但我无法让它适用于站点根目录,即“/”。

我尝试使用空字符串“default.aspx”(这是我保存在根文件夹中的空 aspx 文件,以便与 cassini 和 iis 配合使用)注册一条路由。我明确地将 RouteExistingFiles 设置为 false,但无论我在点击根 url 时做什么,它仍然会打开 default.axpx,它没有继承的代码,并且包含一个简单的 h1 标记来表明我已经点击了它。

我不想更改默认文件以重定向到所需的路由,我只想在找不到其他路由时应用相当于“默认”路由,类似于 MVC。

作为参考,该网站的早期版本没有使用 Web.Routing,但在 web.config 中引用了一个处理程序,该处理程序完全能够拦截对 root 或 default.aspx 的请求。

规格:ASP.NET 3.5sp1、C#、无 Webforms、MVC 或 openrasta。普通的旧 IHttpHandlers。

I am doing some work with Web.Routing, using it to have friendly urls and nice Rest like interfaces to a site that is essentially rendered by a single IHttpHandler. There are no webforms, the handler generates all the html/json and writes it as part of process request.

This works well for things like /Sites/Accounting for example, but I can't get it to work for the site root, i.e. '/'.

I have tried registering a route with an empty string, with 'default.aspx' (which is the empty aspx file I keep in my root folder to play nice with cassini and iis). I set RouteExistingFiles to false explicitly, but whatever I do when hitting the root url it still opens default.axpx, which has no code it inherits from, and contains a simple h1 tag to show that I've hit it.

I don't want to change the default file to redirect to a desired route, I just want the equivalent of a 'default' route that is applied when no other routes are found, similar to MVC.

For reference, the previous version of the site didn't use Web.Routing, but had a handler referenced in the web.config that was perfectly capable of intercepting requests for the root or default.aspx.

Specs: ASP.NET 3.5sp1, C#, no webforms, MVC or openrasta. Plain old IHttpHandlers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

表情可笑 2024-09-04 04:03:05

解决了我自己的问题:问题是集成的 Web 服务器、Cassini 或类似的服务器。似乎它在路由方面表现不佳,默认情况下只会返回 default.aspx 文件,或者如果缺少,则显示目录列表。

将 IIS 与虚拟目录一起使用效果很好,但很烦人(让代码共享者感到沮丧,因为他们在打开我的应用程序时需要设置新的虚拟目录,并且污染了我自己的 IIS 实例。呸。也许我现在会做的,或者手动设置一个新的应用程序,以便我可以使用仅域主机路径,就像实时存在的路径一样。

另一种方法是使用更新版本的 cassini,参见 此处,如果 default.aspx 文件丢失,它可以工作,但我还没有弄清楚如何将它与 Visual Studio 集成,任何帮助将不胜感激,但考虑到我有解决方法,这不是一个大优先事项。

Fixed my own problem: the issue is the integrated web server, Cassini or some such. Seems that it doesnt play nice with routing, and will by default simply return the default.aspx file or, if it is missing, show a directory listing.

Using IIS with a virtual directory works fine, but is annoying (frustrates code sharers because they need to set up new virtual directories when they open my app, and pollutes my own IIS instance. Bah. Probably what I'll do for the moment however, or setup a new application manually so I can use the domain host only path like what will exist in live.

An alternative is to use the updated version of cassini, seen here, which works if the default.aspx file is missing, but I have not worked out how to integrate it with visual studio yet. Any help would be appreciated, but its not a big priority given I have workarounds.

妖妓 2024-09-04 04:03:05

我意识到这是一篇非常旧的帖子,但我刚刚使用 VS2012 遇到了同样的问题,所以我将其发布在这里以防万一。

我通过安装 IIS Express 并将项目设置为在 Visual Studio 中使用 IIS Express。解决了问题。

I realise that this is a really old post, but I just ran into the same problem using VS2012, so I'm posting this here just in case.

I solved the problem by installing IIS Express and setting the project to use IIS Express in Visual Studio. Solved the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文