You will need to manually create the UrlHelper
class and pass the appropriate RequestContext
. It could be done with something like:
var requestContext = HttpContext.Current.Request.RequestContext;
new UrlHelper(requestContext).Action("Index", "MainPage");
However, you are trying to achieve redirection based on authentication. I suggest you look at implementing a custom AuthorizeAttribute
filter to achieve this kind of behavior to be more in line with the framework