Archive for the ‘ASP.NET’ Category
Enums dont implement IEnumerable
9 May, 200810 ASP.NET Performance and Scalability Secrets
5 February, 2008An article by Omar Al Zabir explains 10 easy ways to make ASP.NET and AJAX web sites faster, more scalable and support more traffic at lower cost. Omar Al Zabir is the CTO of Pageflakes one of the best mashups.
Main points he has discussed in this article
- ASP.NET pipeline optimisation
- ASP.NET process configuration optimisation
- Things you must do for ASP.NET before going live
- Content Delivery Network
- Caching AJAX calls on browser
- Making best use of Browser Cache
- On demand progressive UI loading for fast smooth experience
- Optimise ASP.NET 2.0 Profile provider
- How to query ASP.NET 2.0 Membership tables without bringing down the site
- Prevent Denial of Service (DOS) attack
Read the full article at code project 10 ASP.NET Performance and Scalability Secrets
System.Data.DataSetExtensions Config Error in Visual Studio 2008 RTM
3 December, 2007I got the exception shown below when I opened an application that was developed under VS 2008:
ASP.NET runtime error: Could not load file or assembly ‘System.Data.DataSetExtensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ or one of its dependencies. The system cannot find the file specified
What’s happened is there is no more an assembly System.Data.DataSetExtensions with version number 2.0. There is a new version for the same assembly name under 3.5.0.0.
To resolve the problem, simply right-click on the web application, properties, then remove the reference to the 2.0.0.0 assembly.
Then, right-click on the web application solution, Add Reference, locate the System.Data.DataSetExtensions and add a reference to it. You may also need to update the entry web / app.config file under the <assemblies> tag. Update the version to 3.5.0.0
Flickr .Net API
26 November, 2007
Ran into a few permissions problems with this over the weekend when I came to deploying it with ASP.NET
FlickrNet. It is not incredibly web friendly – you need to override where it looks to store its cache. In your root web.config, you need to add the following section to the configSections part, or if there is no configSection piece, add it to the top of the web.config, right after the configuration section starts:
<configSections>
<section name=”flickrNet” type=”FlickrNet.FlickrConfigurationManager,FlickrNet” />
</configSections>
And then add this line within the configuration section:
<flickrNet cacheLocation=”e:\domains\qgyen.net\temp” />
There are a few other issues. First, if you are running under medium trust, with the default configuration, you cannot define configuration sections. Second, if you are in medium trust, the cache location will need to be somewhere within your application’s directories. Medium trust often doesn’t let you read or write outside of the application. Third, you cannot use a string like “~/temp” you need to specify the full path.
I’m in a podcast!
30 July, 2007Have a listen for yourself http://www.craigmurphy.com/blog/?p=610
It was a sound bite taken by Craig after the DeveloperDeveloperDeveloper event held at MS HQ in Reading.
Could this be the end of the pointless Computer Science degree?
17 July, 2007It’s certainly a step in the right direction for Universities. Companies could stand to recruit graduates that can be put to work pretty quickly, dodging the 12 month training process.
Next thing Universities will be incorporating MCTS into the degree :-p
http://www.hope.ac.uk/content/view/203/41/
Could this be the end of the ‘crappy’ coder – with a new wave of trained .NET developers?
Option strict and option explicit defined…
23 January, 2007A friend and coworker asked me today why I use ‘Option Explicit’ and ‘Option Strict’ at the top of all my .net (and for that matter VB6/asp 3.0) classes. I thoguht I’d record the answers here.
‘Option Explicit’ ensures you declare all variables before use. VB.NET doesn’t allow this anymore but in the past it was possible to build an entire application without declaring a single variable!
‘Option Strict’ keeps VB developers coding bad casts as below:
dim x as string = “true”
dim y as boolean = x
or
dim ctl as control
ctl = new textbox
If you’re pure C# you probably can’t believe that this is actually possible. Well it is. More to the point VB developers have bad habits from the ‘days of old’ and code things like this without even batting an eyelid. NOTE: By default VB.NET still allows these bad casts
Option Explicit Statement
By default, the Visual Basic .NET or Visual Basic 2005 compiler enforces explicit variable declaration, which requires that you declare every variable before you use it.
Option Strict Statement
By default, the Visual Basic .NET or Visual Basic 2005 compiler does not enforce strict data typing.
In Visual Basic .NET, you can convert any data type to any other data type implicitly. Data loss can occur when the value of one data type is converted to a data type with less precision or with a smaller capacity. However, you receive a run-time error message if data will be lost in such a conversion. Option Strict notifies you of these types of conversions at compile time so that you can avoid them.
Overloading routines in WebServices
19 January, 2007Web services are also classes just like any other .NET classes. Since a web service is a class it can utilise all the OO features like method overloading. However to use this feature with WebMethods we need toadd a little extra syntax.
Creating WebMethods
Create a WebService that has the following overloaded methods:
public string GetGreeting()
public string GetGreeting(string p_Name)
public string GetGreeting(string p_Name, string p_Message)
All these three methods return variants of a Greeting message. Now mark the methods as Web Methods, simply add the [WebMethod] attribute.
[WebMethod]
public string GetGreeting()
{
return “Hi Guest”;
}[WebMethod]
public string GetGreeting(string p_Name)
{
return “Hi ” + p_Name + “!”;
}[WebMethod]
public string GetGreeting(string p_Name, string p_Message)
{
return “Hi ” + p_Name + “!” + p_Message;
}
Run the WebService in the browser. That should give an error saying that the GetGreeting() methods use the same message name ‘GetGreeting’.
Adding the MessageName property.
Add the MessageName property to the WebMethod attribute as shown below:
[WebMethod]public string GetGreeting()
{
return “Hi Guest”;
}
[WebMethod (MessageName="WithOneString")]
public string GetGreeting(string p_Name)
{
return “Hi ” + p_Name + “!”;
}
[WebMethod (MessageName="WithTwoStrings")]
public string GetGreeting(string p_Name, string p_Message)
{
return “Hi ” + p_Name + “!” + p_Message;
}
Now compile the WebService and run in the browser. You can see that the first method is displayed as GetGreeting but for the second and third method the alias we set using the MessageName property is displayed.
You could of course use the alias’ as your method names – but that’d be taking the fun out of OO
Using the arraylist – populating, sorting and searching
19 December, 2006A friend was asking about sorting the arraylist. I’ve knocked together a sort tutorial on the object and soem of it’s abilities.
Adding Objects to the ArrayList
Adding objects is simple just use the add method:
Dim al As New ArrayList()
al.Add(“This”)
al.Add(“Is”)
al.Add(“My”)
al.Add(“New”)
al.Add(“ArrayList”)
al.Add(“Control”)
This adds 6 new objects to the arraylist.
Reading the Values of the ArrayList
To read the values you can iterate though each of the items in the Item collection like so:
Dim i As Integer
For i = 0 To al.Count – 1
Console.WriteLine(CStr(al.Item(i)))
Next
If you prefer you can use an Enumerator like this:
Dim en As IEnumerator = al.GetEnumerator
While en.MoveNext
Console.WriteLine(en.Current)
End While
Searching The ArrayList
To search for the existence of an object in the ArrayList, you can use the BinarySearch method:
Dim al As New ArrayList()
al.Add(“This”)
al.Add(“Is”)
al.Add(“My”)
al.Add(“New”)
al.Add(“ArrayList”)
al.Add(“Control”)‘Do a case Insensitive search
Dim idx As Integer = al.BinarySearch(“my”, New CaseInsensitiveComparer())If idx > 0 Then
MessageBox.Show(“Found at Index ” & idx)
Else
MessageBox.Show(“Not Found”)
End If
Note that we use a CaseInsensitiveComparer object above, you could also do this:
Dim idx As Integer = al.BinarySearch(“my”)
If you do not specify the IComparer implementation the default is a case sensitive compare. So the line above will return the “Not Found” message.
Sorting the ArrayList
There are a few different options to sorting but the basic is a simple Ascending Case Sensitive Sort:
Dim al As New ArrayList()
al.Add(“This”)
al.Add(“Is”)
al.Add(“My”)
al.Add(“New”)
al.Add(“ArrayList”)
al.Add(“Control”)Console.WriteLine(“Before Sort:”)
WriteElements(al)al.Sort()
‘ Sort descending using this: al.Reverse()WriteElements(al)
Here’s a routine that will write the contents of the arraylist
Private Sub WriteElements(ByVal al As ArrayList)
Dim en As IEnumerator = al.GetEnumeratorWhile en.MoveNext
Console.WriteLine(en.Current)
End While
End Sub
Caputure keypress and raise postback – a javascript function
8 December, 2006I wanted to capture the return/enter key being pressed within a a textbox. Once the return key had been pressed [chr(13)] then I wanted to raise a postback.
Here is the textbox declaration:
<asp:textbox onkeypress=”return captureKeys(event)” id=”querySearch” Runat=”server” />
The following javascript fucntion will capture key presses for IE4/5/6/7, FF 1.0/FF 2.0 and NN6.
function captureKeys (evt) {
var c = document.layers ? evt.which
: document.all ? event.keyCode
: evt.keyCode;
//alert(‘pressed ‘ + String.fromCharCode(c) + ‘(‘ + c + ‘)’);
if (c == 13) //return /enter key
{
if (document.getElementById(‘Top2_searchLinkButton’) != null) {
__doPostBack(‘Top2$searchLinkButton’,”)
return false;
}
return true;
}
If you need for NN4 to capture keypresses in text fields/areas too add
if (document.layers)
document.captureEvents(Event.KEYPRESS);



