Debugging with Response.Write in classic ASP - asp-classic

I am trying to debug some code using Response.Write, but when I run the code it skips over that statement and errors out at some point further in the code.
How can I get my Response.Write statements to show without the other errors coming up?

I quite frequently use Response.End when I have to see a status in a certain place on a page.

We utilize Visual Studio 2008 to debug classic asp pages. You can attach to the IIS process and "step through" the page. Its very sweet. Here are the steps:
Get latest of the classic ASP from source control.
Install IIS (if not already). FYI... I am using IIS 5.1.
Create a virtual directory called "classicDebug" pointing to your local directory (C:\Websites\ClassicWebSite).
View the virtual directory properties, Virtual Directory tab.
Enable the "Script source access" checkbox.
Configuration button, Options tab - check everything.
Debugging tab - check everything.
7a. In the ASP.NET tab, select 2.x
Load up (not run or debug or F5) the website in VS.NET 2008.
Edit your global.asa accordingly (data sources, and paths).
Find the .asp page you want to "step through" and set a break point at the top (or somewhere).
Open IE, and navigate to your page.
Go back to VS.NET and select Debug -> Attach to Process
Check "show processes from all users" and select the process. For me (IIS 5.1), the process name is dllhost.exe running with the IWAM_COMPUTERNAME account w/type "Script, T-SQL, Managed, x86".
Visit your page using IE... VS.NET should break.

Comment out the line which gives the error and see what the respnse.write is displaying is the only thing reasonable.
Don't use the on error resume next while you are developing your pages. You have to make sure that you building your pages correctly and that your are producing correct code. You wont see any errors if you use on error resume next.
on error resume next should only be used, in my opinion, in database actions and in delivered (non-developning) code. In that case you should use the
if Err.Number <> 0 then
construct to test any errors. You simply cannot do that after every line in asp if you have put the on error resume next statement at the top of your code, but it certainly makes sence in database handling code.

You will have to use "on error resume next" statement on top of your ASP page. This will solve your problem when an error occurs it will move to next line rather than throwing an error.
You can check this link http://www.powerasp.com/content/new/on-error-resume-next.asp for reference.
Happy Coding

Try a Response.Flush after your debugging statments, or setting Response.Buffer to false.

This might help as an alternative to response.write.
I put together this ASP include class which works with Firebug+FirePHP. It allows you to log values (including strings, multi-dimensional arrays and even objects created with json.asp) to the firebug console and view ASP's built in collection objects which can help (particularly with Ajax where you can't output debug data without breaking the json response.) Ajax script load times and errors are automatically logged for quick viewing.
https://github.com/dmeagor/ClassicASP-FirePHP
Just include the file and use log(somevalue) to send formatted variables to the firebug console.
Released under MIT open source license

Speaking of alternate options, from David Meagor post, you can also write traces to a file. Here is an example of how to write to files: https://web.archive.org/web/20210506122630/http://www.4guysfromrolla.com/webtech/040699-1.shtml
If you want, you can even put the trace subroutines in an include file and use that in all your pages when you need it.
Another solution that we are using is to put the tracing methods in a .Net assembly, register it as a COM then call it using CreateObject.
These options will let you keep your traces in a file that you can review later and share with other developers.
I personally use a mix of these approaches: I review log files, use breakpoints and even place from time to time a Response.Write.
One other thing: activate and review the IIS logs: they will often tell you on what line your page broke. You can read here how to enable or disable logs for classic ASP: https://technet.microsoft.com/en-us/library/hh831387.aspx.

Related

Unable to make changes to ASP.NET Code Behind while Debugging

I've created a new ASP.NET Web Application for my project. While debugging, Visual Studio is not allowing me to make changes to my code behind (default.aspx.cs).
When I try, I get the "Edit and Continue" dialog letting me know that "Changes are not allowed while code is running or if the option 'Break all processes when one process breaks' is disabled.
but I'm able to edit my default.aspx
Am I missing an option somewhere?
I know exactly what you mean. Turn off "Enable Edit and Continue" setting (in tools->options->debugging->general). Now you can edit .aspx.cs Content while it's debugging on Local IIS.
You are allowed to changes ASPX page because this page is going to be rendered at client side and changes made in page will be directly affected to client browser.
But When you change in CodeBehind visual studio will not allow to change the code because your code needs to be compile again and dll generated to your application needs to be created again with the updated code. That is why it will not allow you to change it.
If you want to change code, you will have to stop the application, change code and run the application again.
If you want to change the value of defined variable at debug time then you can directly change it by moving cursor on it and reassigning value.
Another option to change the value of variable at debug time is from Immediate window.
If you still want to update the code then follow below steps :
Right Click on the Project
Select Properties
Select Web in Right Panel
Check 'Checkbox' at the bottom saying : 'Enable Edit and Continue'
Refer : http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/26/debugging-support-for-64-bit-edit-and-continue-in-visual-studio-2013.aspx
Probably you need to change this when running and debugging multiple projects at the same time:
Break All Processes When One Process Breaks
http://blogs.msdn.com/b/zainnab/archive/2010/10/22/break-all-processes-when-one-process-breaks-vstipdebug0029.aspx
Perhaps yesterday, you was working only with one project and today you are debugging multiple projects. Thats the difference.
Anyway, first answer is good too.

Printing Crystal Reports from a Crystal Reports Viewer (ActiveX, ASP.Net)

I'm having some serious issues trying to get a Crystal Reports report printed from an ASP.Net page. Here is the current setup:
A Crystal Reports viewer is set up on a page. The report appears fine when viewing the report.
The report viewer PrintMode is set to ActiveX
I am setting the report data source from a session variable, as per SAP's recommendation (found in one of their knowledge base articles). The report data source is being set by a call to a WCF service. The data being passed into the report is fine. (Again, the report displays just fine, showing all content like it should).
The build target for the ASP.Net application and related services are x86.
Everything is using Crystal Reports version 13, and the ASP.Net web application is using .Net 4. It is being viewed in Internet Explorer 8.
I've tried checking the ActiveX settings on Internet Explorer 8, and none of them should be a problem (everything is either set to allow or prompt).
The error happens regardless of running it from the IDE or from a set up website on a separate server.
The settings for the application pool in IIS on the other server are set to allow 32 bit applications.
When I click on the Print icon on the report viewer, I get the following error message:
"An communication error occurred. Printing will be stopped."
This same error happens more than one machine. If I click OK on the error message the dialog underneath says "Please wait while the Crystal Reports Print Control is loaded.". If I wait, nothing happens. There is no prompt to install an ActiveX control, and nothing pops up allowing me to select a printer (of which I know several are installed).
I've tried doing the following things, none of which have worked:
Switch the report type to PDF. If I do this, and click the print button on the report viewer I get the following error:
Microsoft JScript runtime error: Object required."
It breaks on this line in particular:
bobj.crv.stateManager.setComponentState('MainContent_reportViewer_UI',eval('('+document.getElementById('_CRYSTALSTATEctl00$MainContent$reportViewer').value+')'));
There are several dynamic images in the report, but all of them are being displayed correctly when viewing the report. They are the only binary objects that I can think of that would be associated with this report. The error is happening in the dynamically created code for the page - not something that I have written.
I've tried manually installing the ActiveX control from the correct .cab file. This made no difference in any of the scenarios.
I've installed the latest Crystal Reports service pack (service pack 3). Again, this didn't change anything.
I've tried setting up a Virtual Directory for the CrystalReportViewers13 inside the Default Web Site, as recommended by some forum posts I came across. This also has had no effect.
Enabling ViewState on the page has no effect on whether printing works or not.
I've tried adding my own print button and a drop down list with a list of available printers. When I click my own custom print button and call PrintToPrinter(), I get the same error message as trying to print a PDF report:
"Microsoft JScript runtime error: Object required"
...and it breaks on the same line as when trying to print a PDF report when clicking the Print button.
I've been beating my head against this for at least a day now, and I'm fresh out of ideas. Anyone have any idea what might be causing this?
EDIT:
Well, here's what I did in order to get things to work. It ended up being a lot simpler of a fix than what I was thinking:
Stuff the entire ReportDocument into the session. Your page load should look something like this:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["report"] != null)
{
reportViewer.ReportSource = Session["report"];
}
BuildReport();
}
Keep the ReportViewer as simple as possible - don't specify the report type (PDF or ActiveX). Setting it to anything seemed to result in problems. This is what it looks like in the page source:
... and that was it. I can't believe I spent about a day trying to get it to work when it ended up being so simple. Hopefully this post helps anyone else facing the same problem.
Its bad idea to store entire report in session if you are receiving lot of user requests.
While working with crystal reports you must reinitialize the report and its login and datasource, parameters etc in each request (post back or no postback does not matter ) before sending out the response. Crystal report does not maintain complete viewstate that is why it should reinitialized each time.
I think you are not reinitializing during postback requests hence the error.
Save yourself the headache and DISABLE activeX printing. It blows up your web server with temp files, only works with IE, and is limited to the number of reports you can print at the same time. Set the print mode to Pdf and be done with it. A lot of browsers can print pdfs directly.
crViewer.PrintMode = PrintMode.Pdf;
I know this question is old, but I thought I'd chime in just in case someone else has this problem.
I found this page had a number of options for problems that I think are very similar to yours. I was getting the titled 'bobj is undefined' error, but all it really comes down to is that IIS can't find a proper path to the JS files for Crystal.
For myself I ended up placing some folders in my aspnet_client directory in the root of my site (wwwroot) and ensuring that NETWORK_SERVICE had access to the aspnet_client folder. I had to do the same with the 'crystalreportviewers' folder from my x86 SAP folder under
'C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports 20XX\crystalreportviewers'
I also had to add the config from that site into my web.config... and then the viewer started working properly.
Hope it helps!
I ran in the similar issue, the report was being generated correctly on the page, but when I try to Zoom, it was saying, "No valid report source is available". To overcome this issue, I simply load the report each time when page is loaded, no matter Postback or normal load.
Also make sure you are properly disposing the Crystal Report Document, otherwise it may start giving "Load Report Failed" error.

Is there anyway to load up a asp.net page object and render its contents to string from a console application?

I am trying to use aspx pages as an email templates. There will likely be a bunch of objects on the page which will be used as replacements in the html. Because it's an aspx page I'll be able to use databinding, repeaters, etc. At run time, I want to be able to instantiate the aspx page from its path, pass in a bunch of properties, and then get the rendered result of the page and email it. This seems pretty straightforward from a asp.net website (maybe using BuildManager or Server.Execute.) However, I want to be able to use the same templates via a console application by just loading up a page object from its filepath. Is this possible?
You could host your own webserver. Like the Cassini webserver.
In my own application (a Windows-based Desktop-CMS), I include a web server, too (non-Cassini). It works very well, also it does not serve ASP.NET but plain, HTML.
As I did some research back then, I first wanted to use the Cassini, too, but at some point, I found out that too much user privileges were required to run it successfully; this may not be an issue to you, but keeping this in mind and try to run it early with the permissions of the later user, might be a good idea.

How to test an ASP page?

I had to code an Active X DLL which is called from an ASP page.
I am convinced (by debug tracing) that my DLL returns the correct value when its function is invoked from the ASP page, but the page does not display the result as it should.
What's the quickest/easiest way to do some debugging? Can I run ASP locally? If so, I can just add a few print()s (or equivalent), unless there is an easy to use FOSS IDE that will allow me to step through the page in a debugger.
Btw, I notice tags for ASP.Net & ASP-classic. The web page is copyright 2002, so I would guess classic (?)
Update: I should have said, I only ave access the browser's "view page source", not to any files that may have been necessary to create the ASP page originally
Thanks for the help. Yes, control panel add/remove windows components, add IIS then copy the ASP file into c:\inetpub\wwwroot sprinkle a few response.write around the ASP code & Bob's your anutie's live-in lover
If it is classic ASP, you can try to to run it (or the part relevant to you) locally. Copy the VB code, put it into a .vbs file, make minimal changes (like using WScript.Echo instead of Response.Write).
You can also run VBScript code with minimal modifications in the VBA editor of MS Office. This way you have a chance to debug the code line-by line.
If none of this is feasible for you, sprinkle Response.Write în the critical sections and comment out any On Error Resume Next statements. This way you can try to spot the error while running the code on the server.

asp.net someusercontrol_ascx is defined in multiple places error

I've had this intermittent issue when using asp.net. My site is dynamically compiled. Sometimes when I modify a user control my web site complains that it is defined in multiple places. It almost seems like the old control did not get removed from the asp.net temporary files and the updated control is compiled to the same directory so it's defined in multiple places. That would make sense to me except for the fact that I have no control over what is in the Temporary ASP.net Files folder.
I've read that having circular references will cause this. I've made sure that I don't have circular references. Even with the simplest site I've seen this happen.
I've noticed that when using Master Pages this error seems to come up a lot more frequently.
I've read that a hotfix tries to fix this issue but I've gotten this error after applying the hotfix.
If I get the file causing the issue and make an edit to it then the error goes away. Even if I just put a space in the file it will resolve the error.
I can also get the error to resolve sometimes by visiting other pages of the site that might not use the user control and hitting refresh. This does not always work.
If I set the site to debug the error never happens. If I set it so that it comiles on a page by page basis then the error does not happen as much but still happens.
Below is what the error looks like.
Compilation Error
Description: An error occurred during the compilation of a
resource required to service this request. Please review
the following specific error details and modify your
source code appropriately.
Compiler Error Message: CS1595: '_ASP.Header_ascx'
is defined in multiple places; using definition
from 'C:\WINNT\Microsoft.NET\Framework\v1.0.3705\Temporary
ASP.NET Files\root\afwew23d\asdfasd423\asdf23.dll'
Edit:
I'm using .net 2.0 (3.5) even though the error above says 1.0. I got that error from another source since I can't reproduce the issue every time. But the type of error is the same.
Edit 2:
Thanks gisresearch for your research. There was one statement in the link you provided:
One caution even if you have debug=false, is that if you go in and change something in one of your aspx pages, this page will have to be recompiled, but this doesn’t cause an appdomain reload so the whole application is not batch compiled again. This has the effect that the page will now get recompiled separately and get its own dll, so don’t change your aspx pages on a live server too often.
There is a setting in machine.config determining how many recompiles are allowed before the app domain restarts, by default it is set to 15, so after 15 recompilations the app domain will restart, just as it would if you touched the web.config or touched the bin directory.
This seems to say that when debug=false and the site has already been visited and compiled, if you change a page it will only compile that one page. That sounds like it could cause problems. I had thought changing a page or user control would cause the entire app to recompile.
Do you have two user controls with the same file name in diferent Folders of your Web App?
That sometimes will cause this issue.
If I set the site to debug the error
never happens.
when debug=true, the asp.net compiler don’t batch compile, when debug=false it does batch compile and may cause this issue.
The Read this post.
There is a conversation about the same issue.
re: ASP.NET Memory: If your application is in production… then why
is debug=true Monday, April 24, 2006
2:39 PM by Robbie Coleman We did get
an error for a UserControl that it
reported it could not load the
FileName_ascx class due to multiple
versions in the Temp ASP.NET folder.
We identified that we had two user
controls with the same file name in
diferent Folders of the same Web App.
The also had diferent namespaces and
never through this exception until we
set debug="false". We even wiped the
Temp ASP.NET directory clean on an
IISreset.
The only way we could fix the error,
was by renaming the ascx file of one
of the two.
Is this correct...? Was there a better
way to fix this?
BTW... [KissUpText] Tess, your posts
have been very helpfull to our
development team, and we really
appreciate all the information you
have given away. [/KissUpText]
re: ASP.NET Memory: If your application is in production… then why
is debug=true Tuesday, April 25, 2006
1:56 AM by Tess Hi Robbie,
Thanks for the nice comment:)
I am assuming that you are getting
"CS1595:
'UserControls.WebUserControl2' is
defined in multiple places; using
definition from
'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary
ASP.NET
Files\usercontrols\293a1a4b\dbb2d387\cisxatg3.dll'
" or similar.
The problem basically occurrs if you
are using src rather than CodeBehind
and your cs or vb files contain a
definition for exactly the same class
in exactly the same namespace. The
error is really the same as what you
would get if you tried to compile a
dll with another class defined twice
in the same namespace.
The reason i am saying it happens when
you use src is because if you would
use CodeBehind you would have gotten
an error at compile time.
If the usercontrols are really the
same I would avoid creating a copy,
and instead using the one from the
other folder. If they are different I
would either give the different names
if possible, and if not, make sure
that the source classes are in
different namespaces, such as
ProjectName.FolderName.MyUserControl
The reason you are seeing it now and
not before is because you are now
batch-compiling everything into one
dll.
Hope this helps.

Resources