Sunday, May 3, 2009
Display QueryString and Form its on Page
2:33 PM |
Posted by
Brian Culver |
Edit Post
I know this probably is one of the most common posts out on the web (for .Net coders), but I can never seem to find it when I need it. So it is here for my reference.
When you are trying to debug an ASP.Net page and you need to see the form collection after a POST or the QueryString (for convenience) for a GET or POST, simply copy the method add it to a page and call it from one of the Page Lifecycle Event Handlers, such as OnInit, OnLoad, etc. I think it is poor practice to hide this output in the body of a page as a comment so I am not doing that (and strongly recommend that you don't do that either) ... simply remove the code or call (if you add it to a library as a static method). I have seen too many people leave the output as commented (html) code ... simply bad.
Nonetheless, here is the code snippet:
Cheers!
When you are trying to debug an ASP.Net page and you need to see the form collection after a POST or the QueryString (for convenience) for a GET or POST, simply copy the method add it to a page and call it from one of the Page Lifecycle Event Handlers, such as OnInit, OnLoad, etc. I think it is poor practice to hide this output in the body of a page as a comment so I am not doing that (and strongly recommend that you don't do that either) ... simply remove the code or call (if you add it to a library as a static method). I have seen too many people leave the output as commented (html) code ... simply bad.
Nonetheless, here is the code snippet:
/// <summary>
/// Display the QueryString Collection and Form Collection information for a ASP.Net Page
/// </summary>
private void RenderRequestInfo() {
//Iterate the Request.QueryString collection
Page.Response.Write(string.Format("<b> Request.QueryString ({0})</b><br />", Page.Request.QueryString.Count.ToString()));
foreach (string queryItem in Page.Request.QueryString) {
Page.Response.Write(queryItem);
try {
Page.Response.Write("='" + HttpUtility.HtmlEncode(Page.Request.QueryString[queryItem]) + "'<br />");
} catch (Exception ex) {
Page.Response.Write(string.Format("=[Error during render.] {0}<br />", ex.Message));
}
}
Page.Response.Write("<br />");
//Iterate the Request.Form collection
Page.Response.Write(string.Format("<b> Request.Form ({0})</b><br />", Page.Request.Form.Count.ToString()));
foreach (string formItem in Page.Request.Form) {
Page.Response.Write(formItem);
try {
Page.Response.Write("='" + HttpUtility.HtmlEncode(Page.Request.Form[formItem]) + "'<br />");
} catch (Exception ex) {
Page.Response.Write(string.Format("=[Error during render.] {0}<br />", ex.Message));
}
}
Page.Response.Write("<br />");
}
Cheers!
Subscribe to:
Post Comments (Atom)
Search This Blog
About Me
Brian Culver is a skilled independent consultant, speaker and Microsoft Certified SharePoint Master in Houston.
Blog Archive
Labels
- sharepoint (5)
- workflows (2)
- BDC (1)
- MOSS Installation (1)
- MOSS Tools (1)
- User Profiles (1)
- VMWare (1)
- approval (1)
- development (1)
- form services (1)
- gimmal group (1)
- groups (1)
- infopath (1)
- licensing (1)
- publishing (1)
- roles (1)
- security (1)
- utilities (1)
- web-enabled forms (1)
0 comments:
Post a Comment