Monday, August 31, 2015

What to know while writing JavaScript (Important Concepts in JavaScript).

While writing JavaScript we Should take care of these important concepts and JavaScript will be fun....
1. Take care of Opening braces while writing functions in JavaScript.
2. Closures in JavaScript
3. Hoisting in JavaScript
4. Module Pattern in JavaScript
5. Less Use Of Global Variable (Scope) in JavaScript

1. Take care of Opening braces while writing functions in JavaScript.
JavaScript Interpreter Adds a Semicolon if the statement is not Closed.
function demo()
{
//your code
}
if you are using this style of function declaration then it may not work as expected because what the interpreter will do with this is like
function demo();  //notice the closing it adds to the declaration
{
//your code
}

The correct way of writing a JavaScript function is.
function demo(){
//your code
}

Hence, Take care of your function declaration and also take care of your closing on your own.

2. Closures in JavaScript
A first-class function that binds to free variables that are defined in its execution environment is a Closure.
var x=1;
function sum(){
    var y=4;
    print(x+y);    //x is global variable.
}

with the concept of closure there is bug that needs to be taken care of while writing functions.
Closure grabs Reference to the variable not the value.

var yourfunc = [];
 for (var i = 0; i < 8; i++) {
    yourfunc[i] = function() {
                               return i; 
                          }; 
> yourfunc[4](); 
8
> yourfunc[6](); 
8
Here all the values return is 7 because only the last value of i is considered, Remember Closure grabs Reference to the variable not the value. And the last value of is 7.
How to take care of this bug?
var yourfunc = [];
for (var i = 0; i < 8; i++) {
     yourfunc[i] = (function(n) {
                              return function() { return n; }
                            })(i);
> yourfunc[4](); 
4
> yourfunc[6](); 
6

3. Hoisting in JavaScript
What will be the result of the following function?
var x= 1;
function yourfunc() {
if (!x) { 
                        var x= 5; } 
alert(x);}
yourfunc();
to your surprise it will be 5, Let me explain why..
Here the first declaration of x
var x= 1;
Assigns 1 to x. within the scope of if statement there is another declaration of x
Hence when if condition is checked it sees the declaration of x in its scope and ignores the global declaration. But here the problem starts, because the x is used before its declaration in if (!x) then the interpreter converts undefined value to false because JavaScript assumes undefined as false. The code with in if statement is executed and the final value of x is 5.Hence while declaring variables in JavaScript you need to consider the Hoisting of variables or you can get unexpected results.


4. Module Pattern in JavaScript
It defines and immediately executes an anonymous function.
syntax:
(function(parameters) { 
....yourcodes;//any thing here will be function scope, not             
 //Global scope.
})(parameters);
Module pattern is a very important concept to use in JavaScript. It helps to create a new Scope and Closure around it.

5. Less Use Of Global Variable (Scope) in JavaScript
Global scope is the most vulnerable part of the JavaScript if you have an api with some global variable then while extending that api may result in unwanted behavior if same variable name is used in the local code. 

Also, this is the place where hackers can use there logic to alter the program logic. Hence, use Module pattern and give no space for global variable in your code.

Monday, June 15, 2015

BIG DATA

BIG DATA

 Traditional approach was to extract the data from distributed systems, store in centralized data warehouse and develop analytics on top of centralized data warehouse. The central data warehouses were the relational database management systems used mainly to processes structured data such as financial transaction, shipping data, employee information. However, with the technological advancement in various fronts, it has become possible to generate large volume of data sets; both structured and unstructured, in high frequency through varieties of data sources. This led to a tipping point when the traditional architecture was not scalable, efficient enough to store, process and retrieve those large volume of data sets. 

Definition
It is the term used to describe the exponential growth, availability and usage of structured and unstructured data. Big Data is becoming global phenomena in all the sectors including government, business and societies because of the availability of high volume of data, efficient and affordable processing technologies leading to more accurate analyses based on facts. The more accurate the analyses are better would be the understanding of business problems, opportunities and threats leading to better decision making for operational excellence in any business.
The relevance and emergence of Big Data have increased because of the 3Vs (Volume, Velocity and Variety) of data. Volumes refer to the large amount of data being generated through a variety of sources. These data could be structured such as financial transaction, invoices, personal detail or unstructured such as twitter/facebook messages, reviews, videos, images etc. Velocity indicates the speed at which the new data is being generated. Social media messages, sensor data are the examples of high volume of data being generated with high velocity. Variety refers to different types of data available for storage, retrieval and analysis. 

Difference between Big Data and Traditional Data
Traditional data includes the data such as documents, finances, stocks and personal files, which are more structured and mostly human generated. Whereas Big Data mainly refers to the large volume of data being generated through a variety of sources, not just human but also machines, processes etc. These data could be social media contents , sensor data , RFID data, scientific research data with millions, billions in numbers and large volume of size.

Why Big Data Matters
In last few years businesses have witnessed rapid growth of data whether it is in retail industry, logistics, financial or health industry.  There are many reasons, which are contributing to the growth of the data.  Total cost of application ownership is being reduced; application providers are offering cloud/subscription based solutions. Internet is becoming accessible to more and more end customers with the availability of smart phones at affordable cost and higher bandwidth (4G). Social media is becoming mainstream of daily life, business, and politics. More and more objects/things are getting connected to Internet (popularly known as Internet of Things) generating data in each stage of supply chain / value chain of businesses. Data is not only being generated by human but also by machines in terms of RFID feeds, medical records, sensor data, scientific data, service logs, web contents, maps, GPS logs etc. Some data are being generated so fast that there is not even time to store it before applying analytics to it.
This phenomenon of exponential growth of structured and unstructured data with higher speed is forcing the business to explore it rather than ignore it. To remain competitive, businesses have to leverage the data they can get within and outside the organization and use it in the decision-making process whether it is to understand the customers, suppliers, employees or the internal/external processes.

How to get a handle on analyzing the big data
The process of getting handle on analyzing the big data starts with the analysis of the company’s business environment, strategies, understanding the sources of data and their relevance in the business. It is also important to know how the data driven companies and other analytical competitors are exploiting Big Data in order to achieve the strategic advantage. The process of understanding big data analytics does not only involve understanding the technical aspects of big data infrastructure like Hadoop but also logical aspects of analytics such as data modeling, mining and its application in business in order to make better decisions. Literature reviews and researches would not be sufficient for a company to get confidence whether the big data analytics is the way forward for them. Companies can actually start a pilot project focusing on one strategic aspect of business whereby Big Data analytics could add value in the decision making process.

Hadoop and MapReduce
Hadoop is an open source software infrastructure that enables the processing of large volume of data sets in distributed clusters of commodity servers. The main advantage of Hadoop is its scalability as the server can be scaled from one to thousands of servers with the possibility of parallel processing (computing). Hadoop has mainly two components a) HDFS and b) MapReduce.  HDFS refers to the Hadoop Distributed File System that spans across all the nodes of the cluster within Hadoop server architecture. Unlike RDBMS, it is schema less architecture, which can easily store different types of structured and unstructured data. Hadoop is also fault tolerant that means if one node fails then it uses other backup nodes and recovers easily.
MapReduce is at the core of Hadoop. It is highly scalable cluster based data processing technology which consists of two main tasks a) Map and b) Reduce, executed in sequential order. The “map” task takes a set of data from source and converts it into key/value pairs. The “reduce” job then takes these key/value pairs outputs from “map” job and combines (reduces) those tuples (rows) into smaller number of tuples. For example, there is a requirement to collect “twitter” data for a newly released song for sentiment analysis. The chosen keywords are “I love it”, “I like it”, “I hate it”. The map job finds these keys and computes to come up with value (count) in each data set stored in a node of HDFS and the “reduce” task combines these computations at all nodes level to come up with final set of computation (e.g. final counts of these key/values). This way it becomes possible to process vast volume of data based on the scalability of the cluster.

Conclusion Data is becoming the energy of 21st century, a very important resource for every organization. The most important challenge would be to implement a sustainable, affordable, stable solution, which could bring insights and knowledge out of the mountains of data generated by human and machines every second. Big Data solution like Hadoop is being increasingly adopted by industries to exploit their structured and unstructured data thereby creating value through the cycle of data information insight knowledge intelligence and developing strategic capability as analytical competitor.  Despite the challenges, more and more organizations are expected to join this bandwagon in coming future.


Reference: A Blog from Javra Software Nepal.

Saturday, May 30, 2015

Few Example for JAVA understanding

1. Write a Java method removeDuplicates that removes all duplicates in a given list.

 Solution:

import java.util.ArrayList;

public class DuplicateTest {

    public static void main(String args[])
    {
        ArrayList<String> list=new ArrayList<String>();
        list.add("good");
        list.add("better");
        list.add("best");
        list.add("best");
        list.add("first");
        list.add("last");
        list.add("last");
        list.add("last");
        list.add("good");
       
        System.out.printf("List Before Duplicate Removal:%s",list);
       
        removeDuplicatesMethod(list);
       
        System.out.printf("\nList After Duplicate Removal:%s",list);
    }

    private static void removeDuplicatesMethod(ArrayList<String> list) {
        // TODO Auto-generated method stub
        for(int i=0;i<list.size();i++)
        {
            for(int k=i+1;k<list.size();k++)
            {
                if(list.get(i).equals(list.get(k)))
                {
                    list.remove(k);
                    k--;
                }
            }
        }
    }
   
   
}

2.  Write a Java method testForSum which determines whether a given array of integers contains three entries whose sum is equal to a given integer.
Solution:

public class TestSumImplementation {
   
    public static void main(String args[])
    {
      
        int[] testdata={5, 1, 23, 21, 17, 2, 3, 9, 12};
        int sum=5;
      
        boolean result= testForSum(testdata,sum);
        System.out.print(result);
    }

    private static boolean testForSum(int[] testdata, int sum) {
        // TODO Auto-generated method stub
        for(int i=0;i<testdata.length-2;i++)
        {
            for(int j=i+1;j<testdata.length-1;j++)
            {
                for(int k=j+1;k<testdata.length;k++ )
                    if(testdata[i]+testdata[j]+testdata[k]==sum) return true;
            }
        }
        return false;
    }
  
   
}

 3. Create your own linked list

Solution:

public class ListNode {
    Object data;
    ListNode nextNode;
  
    public ListNode(Object object)
    {
        data=object;
    }

    public ListNode(Object object,ListNode Node)
    {
        data=object;
        nextNode=Node;
    }
  
    Object getObject()
    {
        return data;
    }
  
    ListNode getNext()
    {
        return nextNode;
    }
}


public class LinkList {
    private ListNode firstNode;
    private ListNode lastNode;
    private String name;
   
    public  LinkList()
    {
        this("list");
    }

    public  LinkList(String listName)
    {
        name=listName;
    }
   
    public void add(Object obj)
    {
        if(isEmpty())
            firstNode=lastNode=new ListNode(obj);
        else
            firstNode=new ListNode(obj,firstNode);
    }
   
    public boolean find(Object obj)
    {
        if(isEmpty())
            return false;
        else
        {
            ListNode current=firstNode;
            while(current.nextNode!=null)
            {
                current=current.nextNode;
                if(obj==current.data)
                    return true;
            }
            return false;
        }
       
    }
   
   
    public boolean isEmpty()
    {
         if(firstNode==null)
             return true;
         else
             return false;
    }
   
    public String toString()
    {
        if(isEmpty())
            return "Empty List";
        else
        {
            ListNode current=firstNode;
            String result="[";
            while(current.nextNode!=null)
            {
                current=current.nextNode;
                result+=(String)current.data+",";
                   
            }
            result+=lastNode.data+"]";
            return result;
        }
    }
   
    public static void main(String args[])
    {
        LinkList list=new LinkList();
       
        list.add("Straight");
        System.out.println(list.toString());
        list.add("Bent");
        System.out.println(list.toString());
        list.add("Equals");
        System.out.println(list.toString());
       
        list.add("Well");
        System.out.println(list.toString());
        list.add("Storm");
        System.out.println(list.toString());
        //System.out.println(list.toString());
        System.out.printf("\nSearch result of well:%s",list.find("Well"));
        System.out.printf("\nSearch result of Strength:%s",list.find("Strength"));
       
       
       
    }
}
4. Permutation:

import java.util.ArrayList;
import java.util.LinkedList;

public class Permutation {
    public static void main(String[] args) {
        for(int[] a :permutationsOf(new int[]{1,2,3,4})){
            for(int b:a){
                System.out.print(b+",");
            }
            System.out.println();
           
        }
       
    }
    static ArrayList<int[]> permutationsOf(int[] arr) {
        ArrayList<int[]> result = new ArrayList<int[]>();
        if (arr.length == 1) {

            result.add(arr);
            return result;
        } else {
            int first=arr[0];
            int[] rest=new int[arr.length-1];
            for(int i=1;i<arr.length;i++){
                rest[i-1]=arr[i];
            }
            ArrayList<int[]> simpler=permutationsOf(rest);
            for(int[] permutation:simpler){
                ArrayList additions=insertAtAllPositions(first,permutation);
                result.addAll(additions);
            }
            return result;
           

        }
    }

    private static ArrayList insertAtAllPositions(int first, int[] permutation) {
        // TODO Auto- generated method stub
        ArrayList<int[]> res=new ArrayList<int[]>();
        for(int i=0;i<permutation.length+1;i++){
            LinkedList<Integer> ll=new LinkedList<Integer>();
            for(int j=0;j<permutation.length;j++){
                ll.add(permutation[j]);
               
               
            }
            ll.add(i, first);
            int[] r=new int[ll.size()];
            int count=0;
            for(int z:ll){
                r[count++]=z;
            }
            res.add(r);
        }
        return res;
    }


}

5. Object Restriction:

public class RestrictInstance {
   
        private static final int limit_ =5; //Set this to whatever you want to restrict
        private static int count =0;
        private RestrictInstance(){}
        public static synchronized RestrictInstance getInstance(){
            if(count<limit_){
                RestrictInstance myClass= new RestrictInstance();
                count++;
                return myClass;
            }
            return null;
        }
       
        public static void main(String args[])
        {
            RestrictInstance a= RestrictInstance.getInstance();
            RestrictInstance a1= RestrictInstance.getInstance();
            RestrictInstance a2= RestrictInstance.getInstance();
            RestrictInstance a3= RestrictInstance.getInstance();
            RestrictInstance a4= RestrictInstance.getInstance();
            RestrictInstance a5= RestrictInstance.getInstance();
           
            System.out.println(a.toString());
            System.out.println(a3.toString());
            System.out.println(a4.toString());
            //System.out.println(a5.toString());
        }
}

Solution to problem 1
package prob1;

public class MyStringList {
      private int size = 0;
      private final int INIT_ARR_SIZE = 2;
      private String[] strArray;
     
      public MyStringList(){
            strArray = new String[INIT_ARR_SIZE];
      }
      public void add(String s) {
            if(size >= strArray.length) resize();
            strArray[size++]=s;
      }
      public boolean find(String s) {
            for(int i = 0; i < size; ++i) {
                  if(s.equals(strArray[i])) return true;
            }
            return false;
      }
      public String get(int i) {
            if(i < 0 || i >= size) return null;
            return strArray[i];
      }
      private void resize() {
            System.out.println("Resizing from size "+strArray.length +"to "+2*strArray.length);
            String[] temp = new String[2*strArray.length];
            for(int i = 0; i < strArray.length; ++i) {
                  temp[i] = strArray[i];
            }
            strArray = temp;
      }
      public static void main(String[] args) {
            MyStringList list = new MyStringList();
     
            for(int i = 0; i < 64; ++i) {
                  list.add("a"+i);
            }
            System.out.println("looking for a3 "+list.find("a3"));
            System.out.println("value at position 43 "+list.get(43));
      }
}

Solution to Problem 2
package prob2;

import java.util.HashMap;
import java.util.Iterator;

public class Employee {
      private String firstName;
      private String lastName;
      private HashMap salaryRecord=new HashMap();
     
      public void addEntry(String date, double salary) {
            salaryRecord.put(date,salary);
      }
      public void printPaymentAmount(String date) {
            Double salaryObject = (Double)salaryRecord.get(date);
            if(salaryObject == null){
                  System.out.println(firstName+" "+lastName+" did not receive a paycheck on "+date);
                 
            }
            else {
                  System.out.println(firstName+" "+lastName+" was paid "+salaryObject.doubleValue()+" on "+date);
            }
           
      }
      public void printAveragePaycheck() {
            Iterator it = salaryRecord.keySet().iterator();
            double accum = 0.0;
            int count = 0;
            while(it.hasNext()){
                  String nextDate = (String)it.next();
                  Double sal = (Double)salaryRecord.get(nextDate);
                  accum += sal.doubleValue();
                  ++count;
            }
            System.out.println("Average paycheck for "+firstName+" "+lastName+" was "+accum/count);
      }
     
      public static void main(String[] args) {
            Employee e = new Employee();
            e.setFirstName("Jim");
            e.setLastName("Jones");
            for(int i = 0; i < 12; ++i) {
                  e.addEntry(i+"/15/2006", 3070+5*i);
            }
            e.printPaymentAmount("3/15/2006");
            e.printPaymentAmount("5/15/2005");
            e.printAveragePaycheck();
           
      }
      public String getFirstName() {
            return firstName;
      }
      public void setFirstName(String firstName) {
            this.firstName = firstName;
      }
      public String getLastName() {
            return lastName;
      }
      public void setLastName(String lastName) {
            this.lastName = lastName;
      }

}

Tuesday, April 7, 2015

25 Funny Situations Of A Programmer's Life



1. When the project manager enters the office




2. When I try to fix a bug at 3 in the morning



3. When I'm told that the module on which I have worked all the week will never be used




4. When the code that I have not tested on dev works perfectly in production




5. When the sales people announce they have sold our product to the customer




6. When sysadmin finally gives us the root access




7. When I launch my script for the first time after several hours of development




8. When I go off for the weekend while everyone else is still trying to fix bugs




9. When the boss is looking for someone to urgently fix a difficult bug




10. When a thing that worked on Friday no longer works on Monday




11. When a bug goes unnoticed during a presentation




12. When a newbie suggests to add a new feature to project




13. When I realize that I have been blocked for two hours because of a forgotten semicolon




14. When the project manager suddenly looks on my screen




15. When customer wants to change specification 2 days before pushing to production




16. When my script finally worked




17. When I'm told that my code is broken in production




18. When I find a solution without searching Google




19. When the intern tells me that "the tests are for those who can not program"




20. When I manage to replace 200 lines of the algorithm by only 10 lines




21. When I return to development of my code that wasn't commented




22. When they tell me the website has to be supported by IE6




23. When a misformed sql query actually returns me the correct results




24. When I start coding without doing analysis first




25. When project manager thinks that I can handle whole project all by myself


Please do share if you liked this article!

Tuesday, February 3, 2015

Natural Sorting Using Linq For DataTable C#.


public partial class MasterDetailLn_LoanIssue : System.Web.UI.Page
{
private void function()
{
DataTable dtLn_LoanPaid = Ln_LoanPaidService.GetLn_LoanByDepartment();
   DataTable dtsorted=new DataTable();
        if(dtLn_LoanPaid!=null &&dtLn_LoanPaid.Rows.Count>0)
         dtsorted= dtLn_LoanPaid.Select().OrderBy(O=>O.Field<String>("PFNo"),new NaturalSortComparer<string>()).CopyToDataTable();
    }
}
public class NaturalSortComparer<T> : IComparer<string>, IDisposable
{
    private bool isAscending;

    public NaturalSortComparer(bool inAscendingOrder = true)
    {
        this.isAscending = inAscendingOrder;
    }

    #region IComparer<string> Members

    public int Compare(string x, string y)
    {
        throw new NotImplementedException();
    }

    #endregion

    #region IComparer<string> Members

    int IComparer<string>.Compare(string x, string y)
    {
        if (x == y)
            return 0;

        string[] x1, y1;

        if (!table.TryGetValue(x, out x1))
        {
            x1 = Regex.Split(x.Replace(" ", ""), "([0-9]+)");
            table.Add(x, x1);
        }

        if (!table.TryGetValue(y, out y1))
        {
            y1 = Regex.Split(y.Replace(" ", ""), "([0-9]+)");
            table.Add(y, y1);
        }

        int returnVal;

        for (int i = 0; i < x1.Length && i < y1.Length; i++)
        {
            if (x1[i] != y1[i])
            {
                returnVal = PartCompare(x1[i], y1[i]);
                return isAscending ? returnVal : -returnVal;
            }
        }

        if (y1.Length > x1.Length)
        {
            returnVal = 1;
        }
        else if (x1.Length > y1.Length)
        {
            returnVal = -1;
        }
        else
        {
            returnVal = 0;
        }

        return isAscending ? returnVal : -returnVal;
    }

    private static int PartCompare(string left, string right)
    {
        int x, y;
        if (!int.TryParse(left, out x))
            return left.CompareTo(right);

        if (!int.TryParse(right, out y))
            return left.CompareTo(right);

        return x.CompareTo(y);
    }

    #endregion

    private Dictionary<string, string[]> table = new Dictionary<string, string[]>();

    public void Dispose()
    {
        table.Clear();
        table = null;
    }
}

Thursday, January 15, 2015

Finding PostBack Control from ClientSide JavaScript in ASP .net.

We can Find the Control Creating PostBack in ASP .net webform from ClientSide Script using following Code and Also can Capture the end of Asynchronous postback event in case of update panel  where generally focus is lost after asynchronous post back.

 $(function () {

 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, e) {
         if (sender._postBackSettings.sourceElement.id == '<%=ddlLedger.ClientID %>')

                       //Your Control creating postback
                      $("#ctl00_ContentPlaceHolder1_ddlSubLedger_chosen .chosen-single").focus();
         else {
                  //do your thing
                }

            });        
});


Hence on endrequest we can get the postback control on completion of post back and capture the after post back event to do what needed to like may be a focus to next control which is usually lost in case we are using update panel or in case of chosen dropdown.

Wednesday, January 7, 2015

Ajax autoComplete extender Full Working example.

In This Example I am going to Show how to use AutoCompleteExtender of AjaxControlToolkit in asp .net.

For this we need a textBox , and one HiddenField for Storing Selected Items Value.

<asp:TextBox ID="txtSubledger" runat="server" Visible="true" AutoPostBack="True"                                                     OnTextChanged="ddlSubLedger_textChanged"></asp:TextBox>
                                              

  <ajax:AutoCompleteExtender ID="AutoCompleteExtender4" MinimumPrefixLength="3" runat="server"
                                                    TargetControlID="txtSubledger" ServiceMethod="GetCompletionListSubledger" FirstRowSelected="True"
                                                    UseContextKey="True" DelimiterCharacters="" Enabled="True">
 </ajax:AutoCompleteExtender>


  <asp:HiddenField runat="server" ID="ddlSubLedger" />


now on code behind we need a webservice for ServiceMethod="GetCompletionListSubledger" 

 [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionListSubledger(string prefixText, int count, string contextKey)
    {
        DataTable dtAN = TblSubLedgerService.getsubldegertablebyename(prefixText);
        Dictionary<string, string> dt = new Dictionary<string, string>();
        foreach (DataRow dr in dtAN.Rows)
        {
            dt.Add(dr["SubLedgerID"].ToString(), dr["SubLedgerName"].ToString());
        }
        return (from m in dt.Values.ToArray<string>() select m).Take(count).ToArray();
    }


a text Changed event for textbox

   protected void ddlSubLedger_textChanged(object sender, EventArgs e)
    {
        if (!string.IsNullOrWhiteSpace(txtSubledger.Text))
            SetModuleNameListforSubledger(txtSubledger.Text, 3);
        else ddlSubLedger.Value = "";
    }
 

text Changed event calls SetModuleNameListforSubledger Which will basically call previous function of web service but will set hidden field in case of selection of any item.

    protected void SetModuleNameListforSubledger(string prefixText, int count)
    {
        DataTable dtAN;
        dtAN = TblSubLedgerService.getsubldegertablebyename(prefixText);
        if (dtAN == null || dtAN.Rows.Count < 1)
        {
            ddlSubLedger.Value = "";
            return;
        }
        ddlSubLedger.Value = dtAN.Rows[0]["SubledgerID"].ToString();
    }

Here, TblSubLedgerService.getsubldegertablebyename(prefixText) is in Service class and will fetch data from the database with filter.

         public static DataTable getsubldegertablebyename(string subledger)
        {
            const string query = "select top(20) SubLedgerID,code+' '+SubLedgerName as SubLedgerName from tbl_SubLedger where  code+' '+SubLedgerName like @Subledger";
            var tbl = DAO.GetDataTable(query, args => args.Add("@Subledger", string.Concat("%", (string.Concat(subledger, "%")))));
            return tbl;
        }


 Now, we can get selected data from autocomplete in hidden field.

Monday, January 5, 2015

Increase Session Time Out in ASP .NET Application.

We Can Increase Session Time Out Using Following Two Methods.

1. Using Web.Config File.
2. Using IIS setting in the windows server(Application Server).

Using Web.Config File.

Using  web.Config file we need to add timeout="minutes" in  sessionstate of system.web section of web.config file.

<system.web>
        <sessionState timeout="540"/>
.....


 Using IIS setting in the windows server(Application Server).


Change the following time-outs in Internet Services Manager .Choose a value greater than the default of 20.
    1. Select Default Web Site > Properties > Home Directory > Application Settings > Configuration > Options.
    2. Enable the session state time-out and set the Session timeout for 60 minutes.

    3. Select Application Pools > DefaultAppPool > Properties.
    4. From the Performance tab under Idle timeout, set Shutdown worker processes after being idle for a value higher than 20.

The default session time-out setting on IIS is 20 minutes but it can be increased to a maximum of 24 hours or 1440 minutes. See Microsoft article Q233477 for details about increasing the timeout in IIS.
Symptom
When returning to the logon page for Web Interface, users often encounter an Error: Your session with the web-server expired. You have been logged out.
Cause
Web Interface 2.0 picks up the session timeout setting from IIS.
Resolution
1. Start Internet Services Manager 5.0.
2. For explicit authentication, right-click the /Citrix/MetaFrameXP/default virtual directory and view the Properties.
    For desktop credentials, pass-through users edit the /Citrix/MetaFrameXP/integrated virtual directory.
For Smart Card users, edit the /Citrix/MetaFrameXP/certificate virtual directory.
3. In the Application Settings section, click Configuration.
4. Select the App Options tab.
5. Ensure Enable session state is selected.
The default session time-out setting on IIS is 20 minutes but it can be increased to a maximum of 24 hours or 1440 minutes. See Microsoft article Q233477 for details about increasing the timeout in IIS.
NFuse Classic 1.71 and earlier
When Internet Explorer is configured never to check for newer versions of Web pages, NFuse Classic will not launch an application after a session is allowed to expire. To reproduce this problem:
    1. Configure your browser settings for 'Temporary Internet files and set Check for newer versions of stored pages to Never.
    2. Log on to Citrix NFuse Classic and view your published applications.
    3. Leave the system idle for 20 minutes or longer so that the Web server session expires.
    4. Click an application icon. The system returns you to the Logon page and a message appears stating that your session expired.
    5. Log on again and click the same application as before. You are again returned to the Logon page even though your session should not have expired this time.
Solutions
      • Clear the Temporary Internet Items folder
      • Upgrade to Web Interface 2.0 or later
      • Set Check for Newer versions of stored pages to Automatically
The default session time-out setting on IIS is 20 minutes but it can be increased to a maximum of 24 hours or 1440 minutes. See Microsoft article Q233477 for details about increasing the timeout in IIS.