简体   繁体   English

URL 重写 asp.net c#

[英]URL Rewriting in asp.net c#

I'm working on a real estate website.我在做一个房地产网站。 It would be ideal to have my client's featured properties have their own unique URL like:让我的客户的特色属性拥有自己独特的 URL 是理想的,例如:

www.realestatewebsite.com/featured/123-fake-st/ www.realestatewebsite.com/featured/123-fake-st/

I'm constructing a CMS for my client so that they can add/delete featured properties in an admin backend, meaning that I need to write a program to automatically add the new URL for them based on the address they input in the database through the CMS.我正在为我的客户构建一个 CMS,以便他们可以在管理后端添加/删除特色属性,这意味着我需要编写一个程序来根据他们在数据库中输入的地址自动添加新的 URL 通过CMS。

I'm new to URL Rewrite.我是 URL 重写的新手。 What would be the best way to go about this? go 关于这个问题的最佳方法是什么? I've considered using RewriterConfig in the web.config, but then I'm worried I would encounter problems writing a program that adds new rules to the web.config file.我曾考虑在 web.config 中使用 RewriterConfig,但后来我担心在编写向 web.config 文件添加新规则的程序时会遇到问题。 I thought about using a regex expression in the RewriterRule to find anything after /featured/ in the URL, but then if I'm just using the address in the LookFor then how would it know which property ID to use in the SendTo?我曾考虑在 RewriterRule 中使用正则表达式来查找 URL 中 /featured/ 之后的任何内容,但是如果我只是在 LookFor 中使用地址,那么它如何知道要在 SendTo 中使用哪个属性 ID?

It would be ideal if I could just have a file put the address after "/featured/" into a string, look in the database for the address and retrieve the Property ID and then redirect the users that way.如果我可以让一个文件将“/featured/”之后的地址放入一个字符串中,在数据库中查找地址并检索属性 ID,然后以这种方式重定向用户,那将是理想的。

As I said, I'm new to URL Rewriting and it would be great if someone could point me in the right direction.正如我所说,我是 URL 重写的新手,如果有人能指出我正确的方向,那就太好了。

Thanks!谢谢!

-Aaron -亚伦

There are different ways of doing this.有不同的方法可以做到这一点。 Common to all solutions are the following:所有解决方案的共同点如下:

  1. Set up a algorithm to create the URIs and store them in the database (changing space to - is a simple way to achieve this.设置一个算法来创建 URI 并将它们存储在数据库中(将空间更改为 - 是实现此目的的简单方法。
  2. Route the URI by making the address string into a parameter通过将地址字符串作为参数来路由 URI

Routing can be done a variety of ways.路由可以通过多种方式完成。

If you have control of the server, or they have control of the server, you have the ability to set up IIS rewriting on the IIS instance on their server ( good starter URI ).如果您可以控制服务器,或者他们可以控制服务器,则您可以在其服务器上的 IIS 实例上设置 IIS 重写(良好的启动器 URI )。

If this is hosted on an ISP, you may not have this option and have to use IIS rewriting and will have to use ASP.NET routing.如果这是托管在 ISP 上,您可能没有此选项,并且必须使用 IIS 重写,并且必须使用 ASP.NET 路由。 Here is a good article to start with to undestand this.是一篇很好的文章,可以开始理解这一点。 If you are using MVC, the routing is "built in".如果您使用的是 MVC,则路由是“内置的”。

I would suggest using URL Rewrite Module for IIS7 , look here: http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/我建议使用URL Rewrite Module for IIS7 ,看这里: http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM