Thursday, December 29, 2011

Unable to start program http://localhost an issue with ie8 and VS2005/2008

I was getting this error when I tried to debug the web application from visual studio. This worked good with ie7 and got error after upgraded to ie8. Since, we do not have adminstrator permissions on our working computers, I was not sure about the solution that were found in the internet.

Finally I forwarded below one to our support team and they said it works.

Modify the registry as described in the second link above.
1.Open RegEdit
2.Browse to HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
3.Add a DWORD value called TabProcGrowth with a value of 0

Good luck for all those who are like me searching for the solution to this issue.

Monday, April 4, 2011

TimeoutException The request channel timed out while waiting for a reply after 00:01:00. WCF web service

The default value for the send timeout is "00:01:00". If the operation requested by the service consuming application takes more than a minute, the service may have completed the operation, but by the time the application gets the response, the application throws the following exception:

TimeoutException The request channel timed out while waiting for a reply after 0
0:01:00. Increase the timeout value passed to the call to Request or increase th
e SendTimeout value on the Binding. The time allotted to this operation may have
 been a portion of a longer timeout.

If we closely observe the exception, it says to increase the SendTimeOut value. So from the client side we have to increase the SendTimeOut value let say to "00:50:00" or some bigger value.

But, how much to increase? That we can find out by cumulative time taken to request the service + operation time of the service + service response time. We may have to check for the most largest operation expected by the application to perform.

Other option is to follow the following link in the code project:

This might resolve the timeout issue.

There was no endpoint listening at https://.... that could accept the message

Most of the times we get this error while consuming the hosted web service. For any exception, the what we must understand is what the exception is speaking about exactly and what is the inner exception.

The inner exception gives more details about the cause of the exception. We may have to pay attention to the details of the inner exception. For example, if the inner exception says "The remote server returned an error: (404) Not Found". If we browse the service directly, you may see the wsdl link and everything may work fine. This irritates most of the programmers.

What is the solution for this problem?
1. Get the log in the IIS server for the service. Also check the service hostname that you are accessing to and the specified one in the WSDL are same.
2. Find out the sub error code for 404 in the log. The error may not be because of the endpoint, but the infrastructure supporting endpoint. May be the resource accessed by the service is locked or not available.
3. If the services are load balanced on two or more servers, check to see if individual servers are responding by making one server passive and other one active.
4. If everything is right, then the issue might be with the load balancer.

Friday, March 4, 2011

Maintain HTTP sessions of a web application in a centralized place

We create so many HTTP sessions and forget to kill them. Or, we create Http session object in different pages for the same functionality. They may or may not be having the same name. This creates so much of confusions and also leads to bugs (abnormal behavior) of the application if they are not properly  controlled or utilized.

The solution is to define any http session at one place (in the class) and use them in the most appropriate and wise manner.

In the APPCode, add a class with name SessionMgr.

public class SessionMgr
      public static string UserID
                 return (string) HttpContext.Current.Session["UserId"];

Like this as many session variables used in the project can be defined in one class and wherever, you need them call them by classname.variable name (SessionMgr.UserID).

In this way, you will always have control over the sessions in your project.

Thursday, March 3, 2011

Custom Event Handler

How to propogate any event for the control in the master page to all the child pages?
This can be achieved by Event Handling in .NET:
1. Create an event class that inherits the EventArgs class.
2. Create a Delegate for handling the event.
3. Declare an event in the master page.
4. Add the event to any of the method which raises the event.

Add the following Event Class in the APP Code folder in the website:
Event Class:
public class ABCCodeChangeEventArgs: EventArgs
                public ABCCodeChangeEventArgs(string toCode)
                                _toCode = toCode;
                private string _toCode;
                public string Code
                                get { return _toCode;}

public delegate void ABCCodeChangeEventHandler(object sender, ABCCodeChangeEventArgs e);

Add the event to any control in the Master page:
public event ABCCodeChangeEventHandler BubbleABCCodeChangedEvent;
protected void ddlDropDown_SelectedIndexChanged(object Sender, EventArgs e)
                ABCCodeChangeEventArgs eventArgs = new
                BubbleABCCodeChangedEvent(this, eventArgs);
Add the following code in other pages in the project:
Page Load Event:
Master.BubbleABCCodeChangedEvent +=new ABCCodeChangeEventHandler(Master_BubbleABCCodeChangedEvent);
Define the method in the page:
void Master_BubbleABCCodeChangedEvent(object sender, ABCCodeChangeEventArgs e)

Common behavior for the aspx pages or common functionality for all the pages

How to make the aspx pages in your project to have common behavior or override the existing behavior of the all aspx pages?
1. Create a base class which inherits System.Web.UI.Page.
2. Write the logic to be implemented in the onload method or any other method where the behavior is expected to change.
3. Include the code to call the base method of the Page class.
4. Make all the aspx.cs classes to inherit the base class.
Basically this is useful when you want to check if a session is alive in the application or redirect the user to the login screen or to check the page permissions based on the role of the user.

public class BaseClass : System.Web.UI.Page
                protected override void OnLoad(EventArgs e)