3

I've found many different variations of this question, but nothing that seems to be exactly what I'm trying to attempt, so please excuse me if it has already been answered.

I have an old WebForms solution that I have completed converted to MVC 4 (C#). I have both projects in separate solutions. I want to completely remove the old WebForms project, solution, and deployed files and redeploy the new MVC 4 site in it's place. That being the case, I don't want to kill all the old URLs. For example, in the WebForms site you could go to:

http://mysite.com/Customers.aspx

in MVC 4, that URL is now:

http://mysite.com/Customers

I would like to setup a Route or a Redirect rule that handles scenarios like that. I'm even fine adding many rules manually as the site really isn't that big. I feel like this should be pretty straightforward, but I'm really new to this space and just can't quite seem to figure out where or what I should be adding.

4

2 に答える 2

0

@brentonが正しい方向に向けてくれたおかげで、ようやくこれを理解しました。私の後にこれを行う人のための完全な手順。

ここにある IIS インスタンスに URL 書き換えモジュールをインストールします。

http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module

Visual Studio の Intellisense は書き換えモジュールを認識しないため、次の手順に従って追加します (必須ではありません)。

https://stackoverflow.com/a/8624558/45077

その後、次のブロックをファイルの<system.WebServer>セクションに追加します。Web.config

<rewrite>
<rules>
    <rule name="Redirect ASPX File to MVC" stopProcessing="true">
        <match url="(.*)\.aspx" />
        <action type="Redirect" url="{R:1}" appendQueryString="false" />
    </rule>
</rules>
</rewrite>
于 2013-02-28T16:14:28.447 に答える
0

次のようなカスタム フィルターを使用してみてください: (このコードはシナリオでテストされていませんが、テスト済みの基本の SSL へのリダイレクトを使用しました)...

using System.Web.Mvc;   
namespace Libraries.Web.Attributes
{
    public class RedirectASPXAttribute : FilterAttribute, IAuthorizationFilter
    {
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var request = filterContext.HttpContext.Request;
            if (request.Url != null && request.Contains(".aspx"))
            {
                var manipulatedRawUrl = request.RawUrl.Remove(request.RawUrl.LastIndexOf(".aspx"), 5);
                filterContext.Result = new RedirectResult("http://" + request.Url.Host + manipulatedRawUrl);
            }
        }
    }
}

次に、コントローラーを属性で装飾するだけです。

[RedirectASPX]
public class HomeController : Controller
{

}

うまくいけば、これは少なくともあなたを正しい方向に向けるでしょう.

于 2013-02-27T16:40:54.380 に答える