Thursday, September 18, 2008

Filter IIS logging

IIS uses a flexible and efficient logging architecture. When a loggable event, usually an HTTP transaction, occurs, IIS calls the selected logging module, which then writes to one of the logs stored in %SystemRoot%\system32\Logfiles\.

Ref: http://msdn.microsoft.com/en-us/library/ms525410.aspx

In case you want your IIS to NOT log specific web requests, then you can run this script:

CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs CREATE W3SVC/1/ROOT/proj1/WhosHere.aspx IIsWebFile
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/1/ROOT/proj1/WhosHere.aspx/DontLog 1

This should remove /proj1/WhosHere.aspx from ever being logged.

If you want IIS to log the page again, then you could replace the '1' with a '0' in the last line of the above script.

Wednesday, September 17, 2008

The Science of PERSUASION

The Science of PERSUASION - how to make the other person feel as if you are just like him/her. Here is how it works:

1. The Principle of Liking: People like those who like them - Uncover your real similarities with people and offer genuine praise
A. Similarity
B. Praise

2. The Principle of Reciprocity: Give what you want to receive – People repay in kind. Smile at someone and he smiles back! Give small gifts to everyone – that makes the other person oblidged.

3. The Principle of Social Proof: People follow the lead of similar others - Use peer power whenever it’s available. Taking testimonials from a similar and already satisfied customer and presenting it to another similar customer helps. Influence is often best exerted horizontally rather than vertically.

4. The Principle of Consistency: People align with their clear commitments - Make their commitments active, public, and voluntary. People should feel committed to what you want them to do. Some people stick to what they commit. Get things in written – Example, if someone commits to a date, ask him to email a memo summarizing things. AND written statements become more powerful when they are made public.

5. The Principle of Authority: People defer to experts – Expose your expertise; don’t assume it’s self-evident. Go to get-togethers to make such discussions which reveal your expertise from your mouth easier – not in a boastful way though.

6. The Principle of Scarcity: People want more of what they can have less of – Highlight unique benefits and exclusive information. Use ‘Loss language’ which says b) works better than a). a) If you do this, then you get this. b) If you do not do this, then you lose all of this. Also, exclusive information is better than widely available data. Eg: This is persuasive: “ I just got this report today. It wont be distributed until next week, but I want to give you an earl look at what it shows” and watch how your listeners lean forward! But remember, not to deceive anyone in this.

Use these 6 principles in combination.

REF: Harnessing the Science of Persuasion by Robert B. Cialdini
- Harvard Business Review Article
Pub. Date: October 01, 2001

Thursday, September 4, 2008

Why use .js file for javascript?

Advantages of writing javascript code in .js file over writing the same in .aspx file under the javascript tags:

1. The code in the .js file can be re-used by different aspx and aspx.cs pages.

2. Once the application using the code is run on the client machine, the .js file sits in the cache of the client and keeps working from there - which could be something useful, specially for cases where you might want to display clock on the web page without a postback; or check network connection constantly on web page and disable the web page buttons in case there is a disconnected network instead of HTTP error messages.

3. This cache re-usage would also speed up the page loading and users of your site would also experience faster page loads.

4. Also, you can hide your javascript code from the users in this way. Users cannot see the javascript code in the .js file when they do 'View Source' on the web page.

Javascript code to check Network connection

Here is the javascript code to check if the network is connected. With the SetTimeout function in the code, the code would run automatically after every 500ms and check for the Network connection. This check would occur without a postback on the page - as it is client side code (javascript - actually more of AJAX). Better to place this code in a separate .js file instead of adding it in the aspx page. You do not need to add any special classes for this AJAX/Javascript code.

function CheckConn()
{
var requestUrl = "https://xyz.com/dev/WhosHere.aspx"

try //CreateXmlHttp() gives an error when there is no network
{
CreateXmlHttp();
if(XmlHttp)
{
XmlHttp.open("GET", requestUrl, false);
XmlHttp.send(null);

if (XmlHttp.status == '200')
{
//When Network connected : Status is 200
}
else
{
//Display error - no need for this ELSE loop though, as the TRY block would catch the error if network is disconnected
}
}
setTimeout('CheckConn()',5*100);
catch(e)
{
//Write the error which should show on network disconnect here instead.
}
setTimeout('CheckConn()',5*100);
}

Client Local Machine name

If you need the client local machine name, then here is the code:

The below code gets the machine name and stores it in a session variable.
Session["MachineName"] = Environment.MachineName; //gets client machine name

You can use Session["MachineName"] simply in the files to refer to session variable which is of type Object. But in case, you need to refer the session variable in the dll classes, then you would need to refer it as:
System.Web.HttpContext.Current.Session["MachineName"]

Get Client local time and GMT settings

To get the client local timeoffset and other timezone related parameters from the client machine in javascript, write the below code in the pre-load event:

protected void Page_PreLoad(object sender, System.EventArgs e)
{
string jScript;
jScript = "";
Page.ClientScript.RegisterStartupScript(this.GetType(), "parentwindow", jScript);
}

Maintain Scrollbar position on .NET page

To maintain the scrollbar position on a page after postback in .net, write this code:

<%@Page smartNavigation="true">
In ASP.NET 2.0, it is MaintainScrollPositionOnPostback="true"

Some Javascript tips (.Net page)

1. Using javascript code of newwindow.focus(), blur() does not shift the focus to the new window, but retains in the old window. For this, use Set SmartNavigation = false in your Page header in the .net page as in the code below:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="smart_tag.aspx.vb" Inherits="abc.smart_tag" smartNavigation="True"%>

2. To open a page in new window from button click.

Write the code below under the buton_click event in code behind on the aspx.cs/aspx.vb page:
Dim js As String
js = ""
Page.RegisterClientScriptBlock("js", js)