TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
MANIMARAN RAMASAMY
NA
66
3k
Pass string from Global.asax to Controller
Apr 18 2019 9:51 PM
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
;
//The below line sending null to controller
//HttpContext.Current.Items["AppErr"] = "You have entered illegal characters : " + illChar.ToString();
//The below session also not working
//HttpContext.Current.Session["AppErrSession"] = "This is test message session";
var tempUrlHelper =
new
UrlHelper(HttpContext.Current.Request.RequestContext);
Response.Redirect(tempUrlHelper.Action(act, ctlr));
}
}
}
}
Reply
Answers (
3
)
send email using Javascript and MVC
500.0 Internal Server Error