Dev

Monday 11 January 2016

Tag libraries, Namespaces

Meaning of  Tag Libraries: 

In a Web application, a common design goal is to separate the display code from business logic. Java tag libraries are one solution to this problem. Tag libraries allow you to isolate business logic from the display code by creating a Tag class (which performs the business logic) and including an HTML-like tag in your JSP page. When the Web server encounters the tag within your JSP page, the Web server will call methods within the corresponding Java Tag class to produce the required HTML content.



Namespaces
Advantages
  • It helps us avoid real name clashes with other XML vocabularies.
  • Moreover, namespaces may be used, if XML documents will be distributed to others, when name collisions may really become an issue.

Disadvantages
  • Namespaces, increases the size of XML documents.
  • With namespaces, we need to be extra careful while writing applications (all our programming expressions, querying & creating the XML nodes must be namespace aware). This namespace-awareness overhead (effort to create, and maintain) should be incurred, only if an application requires it (i.e, if management of name collisions isreally needed).



Sunday 10 January 2016

File Handling

File Handling concept in C#.

File handling simply deal with creating, reading, deleting and editing files. Website can handle local files. It can read from, and write to, a text file on the disk. The code can run on any server with file system privileges—and also a local development machine
There are some methods of File which is mostly used in Real application.
1.    Create :-In this mode New File will be created .If  File is Exist then It will be Overridden.
How to create a File using C# File class ?
In order to create a new File using C# File class , we can call Create method in the File class.
CSharp Code : File.Create("c:\\testFile.txt");

2.     Append :-  In Append mode Existing File will be open and contents will be written from Last .If File  is not Exist then new File will be created. Append mode is used Between two Files.

3.    Create New:-In this mode New File will be created, if File is already Exist then it will thrown Exception.

4.    Open:- In this Existing file will be opened if file  is not Exist then it will be thrown Exception. 

5.    OpenRead:- In this Opens the Existing File for Reading the Contents.

6.    Truncate:-In this  Existing File will be open and the Entire contents of the file will be removed.But if the file is not Exist then it will be thrown Exception.
 StreamReader Class:
§  Flush():- Flush function is used for immediately save the File contents from Buffer to Memory.
§  Close():-Close function is used for closing the file.If we do not write close() statement in our program then File will be always open mode ,then No other person will be used this File at that time. This is the reason for using close statement in  the File Program.
§  Read()- It is used for Reading the Value using File Stream.
§  Read-line():-It is used  for Read  the value  using File Stream in a File Line by Line.
§  Peek():- It returns next value but not use it.
§  Seek():- It is used for Read/Write a values at any positions in a file.
StreamWriter Class:
§  close()-->Close function is used for closing the file.
§  Flush():-Flush function is used for immediately save the File contents from Buffer to Memory.
§  Write():- It is used for writing a File using File stream class.


§  WriteLine():- It is used to write a File Line by Line using File stream.

How a Domain Name is translated to an IP Address?

How a Domain Name is translated to an IP Address?

DNS (Domain Name System) is what translate domain name (for eg. www.google.com) into an IP address that our browser can use (for eg. 173.194.35.148). Before the page is loaded, the DNS must be resolved so the browser can establish a TCP connection to make the HTTP request. The DNS Resolution process starts when the user types a URL address on the browser and hits Enter.

On the Internet, many communications programs deal only with IP addresses, yet allow their users to specify machines in terms of their host names (or alias host names). Or a program which already knows the IP address must determine the domain name for the network to which the machine is connected. Such programs must somehow convert the host names into IP addresses (or vice versa) behind the scenes. How do they achieve this translation between IP addresses and host names?

The mapping of host names to IP addresses is handled through a service called Domain Name Service (DNS). Rather than require individual machines, applications, or users to keep up with the constant changes in host names and IP addresses, a series of special DNS servers across the world (known as "name servers") keep track of the name/address information for all the computers on the Internet. Applications that need to determine an IP address from a host name (or vice versa) contact the local "name server" to supply this information.

For instance, if you use a web browser to check out the site "web.mit.edu", the program actually first contacts your local DNS machine to obtain the IP-address that matches the host name you provided; then the program uses that IP address to complete your request.

DNS is used much more frequently than is usually supposed: virtually every activity that moves information across the network (getting web documents, transferring files, sending or receiving electronic mail) relies on DNS.


Anonymous access and Windows Authentication

Authentication:

Authentication: Authentication is the process of determining the identity of a user based on the user’s credentials. The user’s credentials are usually in the form of user ID and password, which is checked against any credentials' store such as database. If the credentials provided by the user are valid, then the user is considered an authenticated user.
In ASP.NET there are different ways in which authentication is performed as discussed below:

   1)               Anonymous Access: There is no authentication performed and the user is treated as       anonymous user by IIS.

Sometimes it is necessary or possible to access any data from remote server or database without any authenticated person. If the data is easily accessible without any authentication (i.e username and password) that means the user accessing those data or file has an anonymous access. There is no difference between a user who is “anonymously authenticated” and an unauthenticated user. There can be many situations where anonymous authentication is useful.


    2)      Windows Authentication: Provides information on how to use Windows authentication in conjunction with Microsoft Internet Information Services (IIS) authentication to secure ASP.NET applications. This is the default authentication mode in ASP.NET and it is set in web.config file of the application.

Windows Authentication uses the security features of Windows clients and servers. Unlike Basic authentication, initially, it does not prompt users for a user name and password. The current Windows user information on the client computer is supplied by the web browser through a cryptographic exchange involving hashing with the Web server. If the authentication exchange initially fails to identify the user, the web browser will prompt the user for a Windows user account user name and password.

Windows authentication is generally used if the users accessing the application belong to same organization.
This authentication method uses Windows accounts for validating users' credentials. This type of authentication is very good for intranet Web sites where we know our users.


What is session? What are uses of session?

Q. What is session? What are uses of session?
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer rather session is stored in server.
When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc.). By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.

Fig : For every client session data is stored seperately

The following example shows how to create session variables in an ASP.NET page for the first and last name of a user, and set them to values retrieved from TextBox controls.
Session["FirstName"] = FirstNameTextBox.Text;
Session["LastName"] = LastNameTextBox.Text;

and to show this on page:

string username = Session["FirstName"] as string;
label1.Text = "Welcome" + Username;

A session ends if a user has not requested or refreshed a page in the application for a specified period. By default, this is 20 minutes. If you want to set a timeout interval that is shorter or longer than the default, use the Timeout property.
The example below sets a timeout interval of 5 minutes:

<%
Session.Timeout=5
%>
Uses of session
-          Carrying information as a client travels between pages.
-          One page data can be stored in session variable and that data can be accessed from other pages.
-          Session can help to uniquely identify each client from another
-          Session is mostly used in ecommerce sites where there is shopping cart system.
-          It helps maintain user state and data all over the application.
-          It is easy to implement and we can store any kind of object.
-          Stores client data separately.
-          Session is secure and transparent from the user.
Disadvantages of session:
-          Performance overhead in case of large volumes of data/user, because session data is stored in server memory.


Friday 8 January 2016

What are anti overload techniques in web server?

 What are anti overload techniques in web server?
At any time web servers can be overloaded because of:
  • -          Too much legitimate web traffic
  • -          Thousands or even millions of clients hitting the web site in a short interval of time (DDoS) Distributed Denial of Service attacks
  • -          Computer worms
  • -          Millions of infected browsers and/or web servers
  • -          limited on large web sites with very few resources (bandwidth, etc.)
  • -          Client requests are served more slowly and the number of connections increases so much that server limits are reached
  • -          Web servers required  urgent maintenance or upgrade
  • -          Hardware Software failures

To partially overcome load limits and to prevent overload we can use techniques like:
  • -          Managing network traffic by using: Firewalls, Block unwanted traffic
  • -          HTTP traffic managers- redirect or rewrite requests having bad HTTP patterns
  • -          Bandwidth management and traffic shaping
  • -          Deploying web cache techniques
  • -          Use different domains to serve different content (static and dynamic) by separate Web servers,
  • -          Add more hardware resources
  • -          Use many web servers

These technique to limit the load on websites are called anti-overload techniques in web server.


Saturday 2 January 2016

HTTP and FTP Functions

HTTP Functions:
The HTTP functions let you manipulate information sent to the browser by the Web server, before any other output has been sent.
Function
Description
Sends a raw HTTP header to a client
Syntax: header(string, replace, http_response_code)
Returns a list of response headers sent (or ready to send)
Syntax: headers_list()
To determine whether or not the headers have been sent yet, use the headers_sent() function.
Checks if / where the HTTP headers have been sent
Syntax: headers_sent(file,line)
Defines a cookie to be sent along with the rest of the HTTP headers
Syntax: setcookie(name,value,expire,path,domain,secure,httponly);
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too.
Defines a cookie (without URL encoding) to be sent along with the rest of the HTTP headers
Syntax: setrawcookie(name,value,expire,path,domain,secure);

FTP Functions:
The FTP functions give client access to file servers through the File Transfer Protocol (FTP).
The FTP functions are used to open, login and close connections, as well as upload, download, rename, delete, and get information on files from file servers. Not all of the FTP functions will work with every server or return the same results.
Some FTP Functions are given below:
ftp_alloc — Allocates space for a file to be uploaded
ftp_cdup — Changes to the parent directory
ftp_chdir — Changes the current directory on a FTP server
ftp_chmod — Set permissions on a file via FTP
ftp_close — Closes an FTP connection
ftp_connect — Opens an FTP connection
ftp_delete — Deletes a file on the FTP server
ftp_exec — Requests execution of a command on the FTP server
ftp_fget — Downloads a file from the FTP server and saves to an open file
ftp_fput — Uploads from an open file to the FTP server
ftp_get_option — Retrieves various runtime behaviours of the current FTP stream
ftp_get — Downloads a file from the FTP server
ftp_login — Logs in to an FTP connection
ftp_mdtm — Returns the last modified time of the given file
ftp_mkdir — Creates a directory
ftp_nb_continue — Continues retrieving/sending a file (non-blocking)
ftp_nb_fput — Stores a file from an open file to the FTP server (non-blocking)
ftp_nb_get — Retrieves a file from the FTP server and writes it to a local file (non-blocking)
ftp_nb_put — Stores a file on the FTP server (non-blocking)
ftp_nlist — Returns a list of files in the given directory
ftp_put — Uploads a file to the FTP server
ftp_pwd — Returns the current directory name
ftp_quit — Alias of ftp_close
ftp_rename — Renames a file or a directory on the FTP server
ftp_rmdir — Removes a directory
ftp_set_option — Set miscellaneous runtime FTP options
ftp_site — Sends a SITE command to the server
ftp_size — Returns the size of the given file
ftp_ssl_connect — Opens an Secure SSL-FTP connection