如何自动将.html页面重新映射到.aspx页面?

时间:2023-01-27 10:25:23

We have a website; which, till now had only HTML pages. Now we are redeveloping it in ASP .Net.

我们有一个网站;到目前为止只有HTML页面。现在我们正在ASP .Net中重新开发它。

This means that all the .html pages will be changed to .aspx extension. The problem is, there are a lot of external references to these pages, and we dont want to go and chage each and every link to aspx right away.

这意味着所有.html页面都将更改为.aspx扩展名。问题是,对这些页面有很多外部引用,我们不想立即将每个链接转移到aspx。

Is there any way to redirect a link to .html pages to .aspx pages? For example, is there any way that the server checks the file specified, finds out that it links to .html page and automatically opens the .aspx page?

有没有办法将.html页面的链接重定向到.aspx页面?例如,有没有办法服务器检查指定的文件,发现它链接到.html页面并自动打开.aspx页面?

5 个解决方案

#1


1  

if you do some sort of url rewriting you can have all the links stay the same and just serve up the aspx pages, request for index.html gets mapped to index.aspx

如果你做某种url重写你可以让所有的链接保持不变只是提供aspx页面,请求index.html被映射到index.aspx

here's what ms says about asp.net url rewriting:

这是ms关于asp.net url重写的内容:

http://msdn.microsoft.com/en-us/library/ms972974.aspx

#2


3  

I would take this opportunity to leave extensions (.html, .aspx, etc) behind.

我会借此机会留下扩展名(.html,.aspx等)。

For all our major websites we now use a custom mapping system, whereby a virtual page URI is mapped to a specific .aspx (or.html) page. This has a few benefits:

对于我们所有的主要网站,我们现在使用自定义映射系统,其中虚拟页面URI映射到特定的.aspx(or.html)页面。这有一些好处:

  • Your visitors see "nicer" URIs;
  • 您的访问者看到“更好”的URI;

  • You're free to re-organise your site as you see fit, behind the scenes, without breaking existing incoming links;
  • 您可以*地在幕后重新组织您的网站,而不会破坏现有的传入链接;

  • You can use dynamic virtual URIs, eg instead of /Product.aspx?p=Blah, you can use /Products/Blah
  • 您可以使用动态虚拟URI,例如代替/Product.aspx?p=Blah,您可以使用/ Products / Blah

We have our own custom system, but I believe ASP.NET MVC now has this feature built-in.

我们有自己的自定义系统,但我相信ASP.NET MVC现在内置了这个功能。

(If you go down this route, you can add legacy mappings for .html URIs that point to your new .aspx pages).

(如果沿着这条路线前进,可以为.html URI添加指向新.aspx页面的旧映射)。

#3


1  

You might want to look into the ASP.NET System.Web.Routing namespace, which was added in .NET 3.5 SP1 I believe:

您可能想要查看ASP.NET System.Web.Routing命名空间,它是在.NET 3.5 SP1中添加的,我相信:

http://blogs.msdn.com/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx

http://msdn.microsoft.com/en-us/library/system.web.routing.aspx

#4


0  

Here's how we handled a similar situation.

以下是我们处理类似情况的方法。

  1. Setup IIS to map html extension to ASP.Net instead of handling it directly.

    设置IIS将html扩展名映射到ASP.Net而不是直接处理它。

  2. In the HttpApplication.BeginRequest handler see if the request is being made for a html file that has been migrated to aspx if so then serve out the aspx page instead by redirecting the response.

    在HttpApplication.BeginRequest处理程序中,查看是否正在为已迁移到aspx的html文件发出请求,然后通过重定向响应来提供aspx页面。

  3. In case the html fiile hasn't been mapped yet just serve out the static html file.

    如果还没有映射html文件,那么只需提供静态html文件。

#5


0  

Like stusmith touched on, you should not let your underlying technology be exposed (and certainly not mandate) what your URIs look like. The best way is as mentioned to not show any extensions at all, but in the current situation maybe it is possible to configure the system in such a way that .html files are acted upon as if they were .aspx?

就像stusmith所说,你不应该让你的底层技术暴露(当然也不会强制要求)你的URI是什么样的。最好的方法就是提到根本没有显示任何扩展,但在目前的情况下,可能会以这样的方式配置系统:.html文件就好像它们是.aspx一样?

I don't know the first thing about .NET but I assume that this is possible without having to go through too many hoops.

我不知道关于.NET的第一件事,但我认为这是可能的,而不必经历太多的箍。

The second best approach is to rewrite the URIs, but that requires extra work for the server (not much, but it adds up).

第二种最好的方法是重写URI,但这需要额外的服务器工作(不多,但它加起来)。

(Don't redirect with a meta refresh. Every other solution is better.)

(不要使用元刷新重定向。其他所有解决方案都更好。)

#1


1  

if you do some sort of url rewriting you can have all the links stay the same and just serve up the aspx pages, request for index.html gets mapped to index.aspx

如果你做某种url重写你可以让所有的链接保持不变只是提供aspx页面,请求index.html被映射到index.aspx

here's what ms says about asp.net url rewriting:

这是ms关于asp.net url重写的内容:

http://msdn.microsoft.com/en-us/library/ms972974.aspx

#2


3  

I would take this opportunity to leave extensions (.html, .aspx, etc) behind.

我会借此机会留下扩展名(.html,.aspx等)。

For all our major websites we now use a custom mapping system, whereby a virtual page URI is mapped to a specific .aspx (or.html) page. This has a few benefits:

对于我们所有的主要网站,我们现在使用自定义映射系统,其中虚拟页面URI映射到特定的.aspx(or.html)页面。这有一些好处:

  • Your visitors see "nicer" URIs;
  • 您的访问者看到“更好”的URI;

  • You're free to re-organise your site as you see fit, behind the scenes, without breaking existing incoming links;
  • 您可以*地在幕后重新组织您的网站,而不会破坏现有的传入链接;

  • You can use dynamic virtual URIs, eg instead of /Product.aspx?p=Blah, you can use /Products/Blah
  • 您可以使用动态虚拟URI,例如代替/Product.aspx?p=Blah,您可以使用/ Products / Blah

We have our own custom system, but I believe ASP.NET MVC now has this feature built-in.

我们有自己的自定义系统,但我相信ASP.NET MVC现在内置了这个功能。

(If you go down this route, you can add legacy mappings for .html URIs that point to your new .aspx pages).

(如果沿着这条路线前进,可以为.html URI添加指向新.aspx页面的旧映射)。

#3


1  

You might want to look into the ASP.NET System.Web.Routing namespace, which was added in .NET 3.5 SP1 I believe:

您可能想要查看ASP.NET System.Web.Routing命名空间,它是在.NET 3.5 SP1中添加的,我相信:

http://blogs.msdn.com/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx

http://msdn.microsoft.com/en-us/library/system.web.routing.aspx

#4


0  

Here's how we handled a similar situation.

以下是我们处理类似情况的方法。

  1. Setup IIS to map html extension to ASP.Net instead of handling it directly.

    设置IIS将html扩展名映射到ASP.Net而不是直接处理它。

  2. In the HttpApplication.BeginRequest handler see if the request is being made for a html file that has been migrated to aspx if so then serve out the aspx page instead by redirecting the response.

    在HttpApplication.BeginRequest处理程序中,查看是否正在为已迁移到aspx的html文件发出请求,然后通过重定向响应来提供aspx页面。

  3. In case the html fiile hasn't been mapped yet just serve out the static html file.

    如果还没有映射html文件,那么只需提供静态html文件。

#5


0  

Like stusmith touched on, you should not let your underlying technology be exposed (and certainly not mandate) what your URIs look like. The best way is as mentioned to not show any extensions at all, but in the current situation maybe it is possible to configure the system in such a way that .html files are acted upon as if they were .aspx?

就像stusmith所说,你不应该让你的底层技术暴露(当然也不会强制要求)你的URI是什么样的。最好的方法就是提到根本没有显示任何扩展,但在目前的情况下,可能会以这样的方式配置系统:.html文件就好像它们是.aspx一样?

I don't know the first thing about .NET but I assume that this is possible without having to go through too many hoops.

我不知道关于.NET的第一件事,但我认为这是可能的,而不必经历太多的箍。

The second best approach is to rewrite the URIs, but that requires extra work for the server (not much, but it adds up).

第二种最好的方法是重写URI,但这需要额外的服务器工作(不多,但它加起来)。

(Don't redirect with a meta refresh. Every other solution is better.)

(不要使用元刷新重定向。其他所有解决方案都更好。)