Hi,
I am trying to pass string from Global.asax Application_BeginRequest to MVC Controller page.
While passing string, checking the form input and validating data in Global.asax
Application_BeginRequest method. If any illegal charactors found, I have to redirect to the same page with error message what they entered wrong. I don't want to display the error message in URL.
So, I tried through HttpContext.Current.Items["Key"]="test message" and session too.
Please help me, whats wrong with code and how to pass a string value to controller from Global.asax?
Thanks in Advance.
Global.asax Code:
- protected void Application_BeginRequest()
- {
- if (Request.HttpMethod.Equals("post", StringComparison.InvariantCultureIgnoreCase))
- {
- var keys = Request.Form.AllKeys;
- foreach (var obj2 in keys)
- {
- var a = Request.Form.Get(obj2);
- string illChar = UnSafeChar(a);
- if(!string.IsNullOrEmpty(illChar))
- {
- HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current);
- UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
- RouteData routeData = urlHelper.RouteCollection.GetRouteData(currentContext);
- string ctlr = routeData.Values["controller"] as string;
- string act = routeData.Values["action"] as string;
-
-
-
-
- var tempUrlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
- Response.Redirect(tempUrlHelper.Action(act, ctlr));
- }
- }
- }
- }