I had to write some good old classic ASP code today and my classic ASP coding skills are so rusty that I put tons of errors in the code. I'm used to having basic ASP error messages on IIS5 and 6 which usually help me to track down problems. On IIS7 I only got the following though:

An error occurred on the server when processing the URL. Please contact the system administrator

After investigating a bit I figured out that we changed the default for the "scriptErrorSentToBrowser" flag in IIS7. It's now false and you always get the error above. Here is how to change it:

1) Start an elevated command prompt. Right-click the command shell item in the Start-Accessories menu and select "Run as Administrator".

2) Run the following command: %windir%\system32\inetsrv\appcmd set config -section:asp -scriptErrorSentToBrowser:true

Once you are done with debugging your ASP app please set it back to false. There are lots of 'evildoers' out there! :)

Category: aspsecurity
Bookmark and Share

One problem that often tricks me in ASP.net is the presence of null values. This article describes how to deal with null strings and null database values.

Null strings

It is not immediately obvious that a null string is not our old friend "". You would think that if a string contained nothing, it would be null, but it isn't. A null string is a string that hasn't been assigned a value, but an empty string is a string that has been assigned an empty value.

You can check if a string is null by using this:

if (myString == null) { do this or that; }


If you try to find the length of a null string, you can get this rather terse error message:

Object reference not set to an instance of an object.


So, it is best to check that the string isn't null first, then try to find its length. You may end up with a null string if you tried to assign a string to a value in a collection, and the value was not present in the collection. You're unlikely to set a string to null yourself, and due to the fact that they are confusing to work with, I don't recommend trying it.

Null Database Values

You can use the useful IsDBNull method to find out if something you have read from a database is a null value. This is an important thing to do, because often you will assume that a field called "bank_balance" in a database, that is a numeric type, must hold a numeric value. But you'd be wrong, because maybe it holds a null value. So, whenever I am reading from a database, I check if the value is null before getting it:


SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
   if (!reader.IsDBNull(1))
   {
      bool title_only = reader.GetBoolean(1);
   }
}


(For more information about SQL, see my 
SQL Server page.)

In Visual Basic you can do this:


If reader3.Item(2) IsNot DBNull.Value Then hours += reader3.Item(2)


Conclusion

Null can trick you in many ways, so always think "could this value ever contain null?" and if so, take precautions.

Category: .netc#vbasp.net
Bookmark and Share

CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files… ‘Access is denied.’
Do you face this problem lately? I did. I have problem to run ASP.NET web application on a fresh installed server. It cannot run ASP.NET even I install .NET Framework 3.5. Web application can be loaded after I register ASP.NET into IIS by using “aspnet_regiis.exe -i -enable“.

However, I faced the problem statement above. So what is the solution? It have something to do with file permission. Just follow below steps to fix it.
Grant full control to two users of your system “Network Service” and “YourComputerName\IIS_IUSERS” on the following folders.
1. C:\Windows\Temp
2. C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
Restart IIS and try run your web application again.

Hope this guide will help.

Category: asp.net
Bookmark and Share
« NextPage 2 of 2  

Free subscriptions

Enter your email address to receive an email when new note is been added.
We will never share your address, and you can unsubscribe in every email.

$19 VPS Wide Skyscraper