private string GetReferrerControlerName() { var fullUrl = this.Request.UrlReferrer.ToString(); string url = fullUrl; var request = new HttpRequest(null, url, null); var response = new HttpResponse(new StringWriter()); var httpContext = new HttpContext(request, response); var routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext)); var values = routeData.Values; string controllerName = values["controller"].ToString(); return controllerName; }
Thursday, December 27, 2012
Get referrer's controller name in MVC application
Following code retrieves referrer's controller name in .net MVC application:
Subscribe to:
Post Comments (Atom)
thats awesome thank you..!
ReplyDeletethnk u. xcellent
ReplyDeleteWeird thing is that routeData.Values do not contain ID value if provided in url. In case that referrer url contains time consuming loading, is this request fully executed just for finding controller name?
ReplyDelete