Debugging ASP.NET Mobile Forms Page Output
While creating a few mobile forms for my West Wind Web Store applications that manage the remote order management portion of the Admin interface I realized that it's pretty tough to debug the HTML output from a specific device. The issue is that if you hit the mobile page from a SmartPhone, a Windows Web Browser or a WAP phone you get different output. I'm doing this with VS.NET 2005 and well there are a few problems with the output generated.
So the question is how do you debug the output for a specific device? For example, on the SmartPhone HTML output there's no view source. To facilitate this process I decided to add a method to my MobilePage subclass that makes it easy for me to capture the output and write it to disk on the server.
protected string SavePageOutput(HtmlTextWriter writer, string OutputFile)
{
// *** Write the HTML into this string builder
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
MobileTextWriter hWriter = (MobileTextWriter) this.Adapter.CreateTextWriter(sw);
base.Render(hWriter);
// *** store to a string
string PageResult = sb.ToString();
// *** Write it back to the server
writer.Write(PageResult);
if (OutputFile != null && OutputFile != "")
{
StreamWriter ssw = new StreamWriter(OutputFile);
ssw.Write(PageResult);
ssw.Close();
}
return PageResult;
}
To capture the page output all I have to do now is to call this method. To facilitate this process I use a page level define:
protected override void Render(HtmlTextWriter writer)
{
#if (SAVEPAGEOUTPUT)
this.SavePageOutput(writer, Request.PhysicalApplicationPath +
"admin\\mobile\\ShowInvoices_Output.htm");
#else
base.Render(write)
#endif
}
The same approach works for normal Web Pages as well BTW. Among other things this approach can allow you to save the output from every generated page into a store of your choice.
Other Posts you might also like
The Voices of Reason
# re: Debugging ASP.NET Mobile Forms Page Output
How did you capture page output in a module? I can't remember now, but I seem to remember the only way to get the entire output independent of a handler/page is to use a Response.Filter which was a bit of a hassle as you don't get the filter in one chunk. If you can find the code it'd be great to post it here.
As to the browser detection - I want it to happen so ASP.NET generates the right output for the device. I need to capture the actual output for the device to see what gets gen'd, because in Whidbey there are a few odd issues. Most everything renders fine in IE, but with the actual devices things get funky even with Html devices like SmartPhone. Minor stuff mostly like dropped spaces between controls etc.
# re: Debugging ASP.NET Mobile Forms Page Output
JIT Debugging failed with the following error: Access is denied.
JIT Debugging was initiated by the user account 'ServerName\ASPNET'.
Check the documentation index for 'Just-in-time debugging, errors' for more information
I added 'ServerName\ASPNET' into debugger group,but this error message is alway there.
did you get a error message like this?
# re: Debugging ASP.NET Mobile Forms Page Output
But for this specific scenario, I think there's a better way yet. I haven't tried this in VS.NET 2005, but if you know the userAgent string for the device you want to debug, you should be able to create a new <clientTarget> section in web.config. Then set Page.ClientTarget on your page(s) to be that clientTarget. Browser detection will effectively be disabled, and you can test your device HTML in IE.