While migrating a site from a classic asp to MVC, I'm having the problem 开发者_如何学Pythonthat not all controllers are implemented yet. For those which are not implemented, I'd like to serve the classic asp page (say /product.asp?id=123) while maintaining the nice url /product/123. To accomplish this I implemented a dummy ProductController which returns a RedirectResult to the classic asp url. But that changes the url in the browsers navigation bar. Requirement has it, that the urls should always be a clean (mvc) one, eventhough the page has not yet been fully migrated.
If this can't be done using a dummy controller, what would be an alternative option to solve this problem?
Thanks in advance!
I can think two ways to do it:
- In the product controller, execute the
product.asp?id=123
page and return the HTML usingReturn Content(..)
- Add a dummy view product and from there, read the
product.asp?id=123
via Ajax and replace the HTML
But both are cumbersome and might not work if you need to post
from the page
You can also use a URL Rewriter that does not change the browser URL (I have never used it, so can't recommend)
My recommendation is to stick with the old URL as long as you don't migrate them to MVC, and then perform the redirection from the old URL to the new one in global.asax
Probably the simplest solution would be to use Server.Transfer which in contrast to Response.Redirect leaves the requested URL as it is.
I stand corrected: It is indeed not possible to Server.Transfer from a .aspx page to an .asp page.
It is however possible using Server.TransferRequest but it requires IIS7 with integrated pipeline mode.
ASP.NET Placeholder Page
<% Server.TransferRequest("Index.asp", true); %>
ASP Target Page
<%@ language="vbscript" %>
<% Response.Write(Request.QueryString("msg")) %>
Usage
http://yoursite/Index.aspx?msg=Hello%20World!
精彩评论