IIS - ASP.NET MVC redirection

2019-06-07 20:27发布

问题:

I have two applications using ASP.NET MVC, each with multiple controllers.

I want to do a redirect from application A to application B, but only for a single route on application A (one controller).

Eg.

/applicationA/issue/* should redirect to /applicationB/issue/

/applicationA/quality/ should not redirect

The examples for IIS redirection are showing me examples of how to click on a file/folder and enable redirection, but I'm trying to do a route, not a physical path.

I don't want to modify the ASP.NET source (if at all possible).

Thanks.

edit - this is in IIS6 on Win2k3.

回答1:

Yeah, that last bit is a real caveat. If this were on IIS7, it'd be 100% easier!

You could download another app to do the redirecting work, but then it wouldn't be hard to edit the MVC app. Assuming that /issue/ and /quality/ are different routes, why not just do something like this:

public class MyController
{
  public RedirectResult Issue()
  {
    //return as a redirect
    return Redirect("http://applicationb/issue");
  }

  public ActionResult Quality()
  {
    //This is here to show that, instead of redirecting, it returns a view.
    return View();
  }
}


回答2:

You could use URLRewriting.NET to do the redirection based on a regex pattern.