Friday, September 9, 2011

Simple Steps to Get 2D QR Code

A QR code (Quick Response code) is a type of matrix barcode or two-dimensional code that can be scanned by smartphone cameras to automatically pull up text, photos, videos, music and URLs. There are variety of ways these QR codes can be used, agreed depends upon creativity, like marketing, as a contact card, displaying URL, labelling products, on T-shirts and thers.

A QR Code that contains this article's URL can be seen below for an example:

Figure 1.


Now lets see a simple example to create a 2D QR Code with the help of Google chart API. In this example we will display this article URL in QR code. This is the URL we just need to get the 2D QR code image:
chs=300x300 means we need 300x300 size of image.

cht=qr means our chart type is QR code.

chld=|3 sets the margin around the matrix for styling purpose. It is optional if you do not provide it default will be 4. See figure 2 the red line represents the margin.

chl=http%3A%2F%2Fmmabdullah.blogspot.com%2F2011%2F09%2Fsimple-steps-to-get-2d-qr-code.html URL encoded URL or data you want to see in the QR Code.

Figure 2.


 OK this was about the few parameters you can see details here. And Google has also provided a chart wizard and it is really useful. Now we only have the URL to get the image how to show it on page? Here it is just give this URL as your image source in image tag.
I hope this will help some one.

Thursday, September 8, 2011

Increase or Decrease Session Timeout Limit in ASP.NET

In ASP.NET the default session timeout is 20 minutes. To increase or decrease this timeout for an application you just need to add an entry in web.config file in <system.web> section. Like this:

If form authentication is being used then you need to add timeout for forms too as it uses its own. This form authentication timeout will send the user to login page with the session timeout still active (if you have set larger session timeout then forms).
Another way to set session timeout is through IIS. These are the steps for IIS 7.
  1. Open IIS 7
  2. Navigate to your website and select it.
  3. In feature view double click on ASP. See figure 1.
  4. Now find the Session Properties under Services. Expand it and set your desired Time-out there. See figure 2.

Figure 1.


Figure 2


Reference: http://technet.microsoft.com/en-us/library/cc725820%28WS.10%29.aspx

Tuesday, March 15, 2011

Easy way to replicate/repeat string or characters

You may have come across a scenario to display some special character, like '*', in place of user's password in some control or displaying some repeated strings or characters like:

0000001
0000002
0000003
0000103

Here I will show two ways of doing so.
string sFiveZeros = new String('0', 5);
Console.WriteLine(sFiveZeros);
//Output: 00000


string sSevenStars = new String('*', 7);
Console.WriteLine(sSevenStars);
//Output: *******

Now the other way is a mix of string.Concat() and System.Collections.ArrayList.Repeat() methods.
string sRepeated123 = string.Concat(System.Collections.ArrayList.Repeat("123", 5).ToArray());
Console.WriteLine(sRepeated123);
//Output: 123123123123123


string sRepeatedAbc = string.Concat(System.Collections.ArrayList.Repeat("abc", 5).ToArray());
Console.WriteLine(sRepeatedAbc);
//Output: abcabcabcabcabc