ASP.NET - 建立自己的路由系统 [英] ASP.NET - Building your own routing system

查看:196
本文介绍了ASP.NET - 建立自己的路由系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的一个项目,我建立在PHP我自己的MVC框架。其中一个我实现的事情是一个路由系统。我用Apache的mod_rewrite所有请求发送到index.php文件,然后解析URI中提取信息和路由请求。

In a recent project, I built my own MVC framework in PHP. One of the things I implemented was a routing system. I used Apache's mod_rewrite to send all requests to index.php, and then parsed the URI to extract information and route the request.

我现在涉足于ASP.NET,我想知道是否/如何我可能会进行类似的东西。有没有一种方法来路由所有请求(类似的方式话语preSS了它)一个页面,执行中央的路线处理?我知道为ASP.NET MVC框架,但我想带刺在这个自己因为我周围的修修补补和学习。

I'm dabbling in ASP.NET now, and I'm wondering if/how I might perform something similar. Is there a way to route all requests (similar to the way WordPress does it) to one page where central route processing is performed? I'm aware of the MVC framework for ASP.NET, but I'd like to take a stab at this myself as I'm tinkering around and learning.

编辑:
顺便说一句,我的托管服务提供商运行IIS 6

BTW, my hosting provider runs IIS 6

推荐答案

这将是一个很长的答案,因为我想确保你完全明白你可以完成你想做的事情的所有方式。

This is going to be a long answer, because I want to make sure you are fully aware of all the ways you can accomplish what you want to do.

路由引擎,权力的ASP.NET MVC框架将与传统的ASP.NET框架。您可以使用RouteTable和分配航线优势,就像你在一个ASP.NET MVC应用程序会。你只是没有得到在传统的ASP.NET网站的MVC部分。这是ASP.NET框架一个巨大的提升,这是伟大的,看到他们重新使用code并使其在两个框架工作。如果您想了解更多关于这一点,看看ScottGu的的帖子,向下滚动到URL路由改进。另外这里是一个关于如何使用参考通过菲尔哈克中的WebForms的System.Web.Routing。

The routing engine that powers the ASP.NET MVC Framework will work with the traditional ASP.NET Framework. You can take advantage of using the RouteTable and assigning routes, just like you would in an ASP.NET MVC application. You just don't get the MVC portion in traditional ASP.NET sites. That was a huge enhancement for the ASP.NET Framework and it was great to see them reuse that code and make it work in both frameworks. If you want to learn more about this, check out ScottGu's post and scroll down to URL Routing Improvements. Also here is a reference on how to use the System.Web.Routing in WebForms by Phil Haack.

现在,如果你仍然想编写你自己。你需要学习ASP.NET HTTP管道以及如何实现的 IHttpModule的的IHttpHandler 以接口创建自己的HttpModule或HttpHandler的类来处理你的路由。这些接口编写自己的路由引擎的关键。为了帮助把这些接口处于工作的例子,我不建议这样 MSDN文章就够了。它显示了如何使用两种界面,并解释差异创建自​​己的路由/ URL重写引擎时。

Now, if you still want to write you own. You will need to learn the ASP.NET HTTP pipeline and how to implement the IHttpModule and the IHttpHandler interfaces to create your own HttpModule or HttpHandler class to handle your routing. These interfaces are the key in writing your own routing engine. To help put those interfaces in a working example, I couldn't recommend this MSDN article enough. It shows you how to with either interface and explains the differences when creating your own routing/url rewriting engine.

现在,如果你发现了,这可能是很多到你。还有,你可以使用谁已经写路由/ URL在.NET中重写引擎人们第三方库。下面是我看到的不是很久以前问的你用什么网址重写为ASP.Net?就在这里左右。

Now, if you find out that this might be to much for you. There are third party libraries you can use of people who already wrote a routing/url rewriting engine in .NET. Here is a question that I saw not to long ago asking "What Url rewriter do you use for ASP.Net?" right here on SO.

这篇关于ASP.NET - 建立自己的路由系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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