Redirect from webform to MVC ..getting errors

2019-09-02 21:24发布

问题:

I am trying out MVC in existing MVC application . I want to do redirect from webform which is in 'Folder1' to MVC Homecontroller which is in Controllers folder ,same level as Folder1.
I tried this ,its The controller for path '/' was not found or does not implement IController.

UrlHelper urlHelp = new UrlHelper(HttpContext.Current.Request.RequestContext);   
Response.Redirect(urlHelp.Action("About", "Home"), false);

and even tried with

Response.Redirect(HttpRuntime.AppDomainAppVirtualPath + "Home/Index");

even tried this

UrlHelper urlHelp = new UrlHelper(HttpContext.Current.Request.RequestContext);           
Response.Redirect(urlHelp.Action("Index", "Home",new { area = string.Empty }),false);

didn`t work out ..Anybody have idea?

回答1:

Try this?

UrlHelper urlHelp = new UrlHelper(Request.RequestContext);
Response.Redirect(Request.Url.GetLeftPart(System.UriPartial.Authority) + urlHelp.Action("About", "Home"), false);