旧的经典ASP页面陷入MVC路线 [英] Old Classic ASP pages getting caught in MVC Route

查看:85
本文介绍了旧的经典ASP页面陷入MVC路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将现有的经典ASP网站转换为(VB)MVC,并且我不希望任何现有的URL中断.我已经阅读了许多文章(例如这样的文章:将经典ASP请求路由至). NET-SEO重定向),了解如何执行正确的301重定向.在最新的MVC版本中,我已经收集了

I am converting an existing classic ASP website to (VB) MVC and I don't want any of the existing URLs to break. I have read many posts (like this one: Routing Classic ASP Requests To .NET - SEO Redirects) about how to do the proper 301 redirect. With the latest MVC release, I've gathered that

Response.RedirectPermanent(objRedirect.new_url, True)

就是所有需要的东西.

我已经在数据库表中输入了我所有的旧URL以及新URL的对应列.我已经在自定义404页面中添加了代码以获取原始网址:

I have entered all of my old URLs in a database table with a corresponding column of the new URL. I have added code in my custom 404 page to get the original URL:

Dim strURL As String = Request.RawUrl.Substring(Request.RawUrl.IndexOf("aspxerrorpath=") + 15).ToLower()

所以我可以在数据库中查找它. (有趣的旁注,MSDN的文档位于此处-重定向模式-似乎在说,如果我在web.config的CustomErrors部分中设置RedirectMode = ResponseRewrite,则不必担心执行上述操作,但是当我尝试执行此操作时,我会收到IIS错误提示它不会提供ASP页?!?!?)

so I can look it up in the database. (Interesting sidenote, MSDN's documentation here - Redirect Mode - seems to say that if I set RedirectMode=ResponseRewrite in the CustomErrors section of my web.config, I won't have to worry about doing the above, but when I've tried that, I get IIS errors saying it won't serve an ASP page?!?!?)

我遇到的问题是,与新的MVC路由具有相同目录的我的旧的,经典的ASP URL都以某种方式进行了部分路由.例如,在我的错误页面的上述strURL变量中,"/test/default.asp"显示为"/test/test".

The problem I am encountering is that any of my old, Classic ASP URLs that have the same directory as a new MVC route are somehow being partially routed. For example, "/test/default.asp" shows up as "/test/test" in the above strURL variable of my error page.

我确实有一个用于测试"的路由设置:

I do have a route setup for "test":

routes.MapRoute("Test", _
                "test/{action}", _
                New With {.controller = "test", .action = "index"})

在Global.aspx.vb中,但是我还尝试了所有可能的方法来忽略路由中的所有ASP页(似乎无济于事).这是我所做的尝试(我确实看到了一个旧的-2008年-

in Global.aspx.vb, but I also have tried every conceivable way to ignore all ASP pages in routes (seemingly to no avail). Here are the attempts I've made (I did see one old - 2008 - post by Phil Haack that said I could only have one of these "catch all" ignore routes, but don't know if that's still valid or not?):

routes.IgnoreRoute("{file}.asp")
routes.Ignore("{resource}.asp/{*pathInfo}")
routes.IgnoreRoute("{resource}.asp/{*pathInfo}")
routes.Add(New Route("{resource}.asp/{*pathInfo}", New StopRoutingHandler()))

,它们似乎都没有任何区别(显然我一次都尝试了一次).

and none of them seemed to make any difference (I tried them all one at a time obviously).

这也不只是一种路由-在旧站点上存在的,与新站点上的命名路由匹配的任何目录都将发生这种情况.

This isn't isolated to just one route either - it occurs for any directories that existed on the old site that match a named route on the new site.

在此先感谢您提出的所有建议!

Thanks in advance for any and all suggestions you have!

更新:这是我发现的另外2个问题":

UPDATE: Here are 2 more "issues" I've discovered:

  1. 我正在失去原始的查询字符串.因此,如果请求了product.asp?id = 1,那么我在错误页面上所拥有的就是product.asp(任何想法如何获取/保存原始查询字符串?)
  2. 我的另一条路线如下:

  1. I am loosing the original querystring. So, if product.asp?id=1 is requested, all I have in the error page is product.asp (any idea how to get at/save the original querystring?)
  2. Another one of my routes looks like this:

routes.MapRoute("IndependentSales",_ 独立销售/{action}",_ {.controller ="independentsales",.action ="index"}的新功能)

routes.MapRoute("IndependentSales", _ "independentsales/{action}", _ New With {.controller = "independentsales", .action = "index"})

,当我请求"/resale/default.asp"时,它转到"resale/independentsales".这是怎么回事?

and when I request "/resale/default.asp", it goes to "resale/independentsales". WHAT is up with that???

推荐答案

好吧,经过数小时的阅读/研究/调试,我得出的结论是我没有做错任何事情,并且有些东西笨拙"在Visual Studio,.NET,MVC中……有些东西!我是对的!我从头开始创建了一个新项目,将我的所有代码复制到了那里,一切都按预期进行了!

OK, after hours and hours of reading/researching/debugging, I came to the conclusion that I wasn't doing anything wrong and that there was something "buggy" in Visual Studio, .NET, MVC ... something! And I was right! I created a new project from scratch, copied all my code over there and everything worked as it should!

(好吧,我不确定应有的正确性"是否正确,但是我确实得到了我想要的功能代码.对ASP页的请求仍然出现在MvcApplication_BeginRequest上,我认为不应该这样做)我的IgnoreRoute条目????-但至少扩展名到那里时还在那里,所以我可以在数据库中查找ASP页并进行重定向!)

(Well, I'm not sure "as it should" is correct, but I did get my code to function the way I wanted. Requests for ASP pages still hit the MvcApplication_BeginRequest - which I don't think they should with my IgnoreRoute entries???? - but at least the extension was still there when it got there, so I could look-up the ASP page in my database and do the redirect!)

所以,这可能对我来说是独一无二的,但是也许我可以省去其他人的挫败感……如果您认为自己的一切都正确的话,也许可以!创建一个新项目,然后尝试!

So, this may have been unique to me, but maybe I can save others hours of frustration ... if you think you have everything correct, maybe you do! Create a new project and try that!

...成为一名程序员真是太糟糕了! ;-D

... It sucks to be a programmer! ;-D

(思考……我没有加回到我的新项目中的三件事是:

(Musings ... The 3 things that I didn't add back into my new project were:

  1. 日志记录工具ELMAH
  2. RouteMagic DLL
  3. 和RouteDebugger.dll.

我可以尝试从我的原始项目中减去它们,然后看看结果如何.鉴于ELMAH的受欢迎程度以及撰写路线的人,我无法想象它们会有问题,但谁知道...?)

I may try subtracting them from my original project and see how that goes. Given the popularity of ELMAH and who wrote the route ones, I can't imagine that there would be a problem with them, but who knows ...?)

这篇关于旧的经典ASP页面陷入MVC路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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