In asp.net mvc application, i am trying to redirect to new route in Application_AuthenticateRequest.If the user is not authenticated, then i am redirecting to different url. Following is the code,
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
var loginUrl = urlHelper.Action("Login", "Default");
Response.Redirect(loginUrl);
}
In this above code, urlHelper.Action method returns empty string even after route registration happens at Application_Start event.
Any idea to resolve this error?
Following is the RouteConfiguration in Application_Start,
RouteTable.Routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional });