Tuesday, April 16, 2019

ASP.Net Diagnostic page to dump request and environment for troubleshooting

It is often seen that we need to dump all the request variables such as headers and all to do troubleshooting. Many things can be dumped using IIS logs itself either by enabling those or by adding extended data fields. Refer below link for details on extended logging.
https://docs.microsoft.com/en-us/iis/extensions/advanced-logging-module/advanced-logging-for-iis-custom-logging

But in some scenarios that is not enough. For example to ensure that the user name / alias is correctly obtained in ASP.Net code. In those scenarios, it is better to dump using custom code. Below is a code snippet which uses ASP.Net template techniques to dump http request and environment variables such as user name etc...

It doesn't need any code behind or pre-compilation. Just save this as file with .aspx extension say dump.aspx.


Running the dump.aspx

Place into the folder and browse that file as
http://<FQDN>/<app name if applicable>/dump.aspx

eg: https://localhost/MyApp/dump.aspx

It is advised just put this file when we debug and not to add as part of application. But if permitted  check in this file into source control so that the troubleshooting will be much easier.

This is tested mainly in .Net Full Framework. Yet to check with .Net Core.

References

The problem has already been faced by many and there are already enough links where people shared the solution. Since every solution is unique putting one more along with some below.

https://code.msdn.microsoft.com/ASPNET-Diagnostic-page-to-9a029c20
https://pedrosneglectedtechblog.blogspot.com/2010/02/quick-and-easy-http-header-dump-aspnet.html
https://blogs.msdn.microsoft.com/friis/2013/01/08/asp-net-authentication-test-page/

No comments: