Dev

Tuesday, 29 December 2015

Login Page in asp.net


Home.aspx

<html>
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="Label1" runat="server" Text="User name:"></asp:Label>
        <asp:TextBox ID="Text_Username" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Label ID="Label2" runat="server" Text="password"></asp:Label>
        <asp:TextBox ID="Text_Pwd" runat="server"></asp:TextBox>
   
        <br />
        <br />
        <asp:Label ID="LabelError" runat="server" Text="Label"></asp:Label>
   
        <br />
        <br />
        <asp:Button ID="Btn_Login" runat="server" Text="Login" OnClick="Btn_Login_Click" />
        <asp:Button ID="Btn_Cancle" runat="server" Text="Cancle" OnClick="Btn_Cancle_Click" />
   
    </div>
    </form>
</body>

</html>



Home.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Btn_Login_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("server=NameofServer;user id=sa; pwd=123; database=MyDatabase ");
        con.Open();
        string query= "SELECT userName, password FROM tbl_User WHERE userName='"+Text_Username.Text+ "'AND pwd='"+Text_Pwd.Text"'";
        SqlCommand com = new SqlCommand(query, con);
        SqlDataReader dr = com.ExecuteReader();
        if(dr.HasRows==true)
        {
            dr.Read();
            if (dr[0].ToString() == Text_Username.Text && dr[1].ToString() == Text_Pwd.Text)
            {
                Response.Redirect("Welcomepage.aspx");
            }
        }
        else{
            LabelError.Text="! Invalid UserName or Password !Try again with user name and password";
       
        }
    }
    protected void Btn_Cancle_Click(object sender, EventArgs e)
    {
        Text_Username.Text = "";
    }
}

Saturday, 26 December 2015

Difference Between GET and POST

GET
POST
We can only send limited data with GET method
we can send large amount of data with POST
GET method is not secure because data is exposed in the URL
POST method is secure because data is sent in request body
GET is the default HTTP method
We need to specify method as POST to send request with POST method.
You can bookmark GET request for e.g. Google Search.
you cannot bookmark a POST request
GET request is also cacheable
you cannot cache POST requests
GET sends data as part of URI
while POST method sends data as HTTP content
GET requests are sent as a query string on the URL:
for example:
GET index.html?name1=value&name2=value
POST requests are sent in the body of the HTTP request: for example:
POST /index.html
There is a limitation on sending data using GET method
It means we can transfer less data to sever.
POST doesn't have such limits. It means we can send large data to server.

HTTP Protocol Methods


What are HTTP Protocol Methods? Explain.

The HTTP methods are given below. These method names are case sensitive and they must be used in uppercase.
GET Method
A GET request retrieves data from a web server by specifying parameters in the URL portion of the request. This is the main method used for document retrieval.
POST Method
The POST method is used when you want to send some data to the server, for example, file update, form data, etc.
HEAD Method
The HEAD method is functionally similar to GET, except that the server replies with a response line and headers, but no entity-body.
PUT Method
The PUT method is used to request the server to store the included entity-body at a location specified by the given URL.
DELETE Method
The DELETE method is used to request the server to delete a file at a location specified by the given URL.
CONNECT Method
The CONNECT method is used by the client to establish a network connection to a web server over HTTP.
OPTIONS Method
The OPTIONS method is used by the client to find out the HTTP methods and other options supported by a web server. The client can specify a URL for the OPTIONS method, or an asterisk (*) to refer to the entire server.
TRACE Method

The TRACE method is used to echo the contents of an HTTP Request back to the requester which can be used for debugging purpose at the time of development.

Sunday, 13 December 2015

XML Schema Definition(SXD) an example

An XSD(XML Schema Definition) Example:
XML file  "shiporder.xml":

<?xml version="1.0" encoding="UTF-8"?>

<shiporder orderid="889923"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation="shiporder.xsd">
  <orderperson>John Smith</orderperson>
  <shipto>
    <name>Ola Nordmann</name>
    <address>Langgt 23</address>
    <city>4000 Stavanger</city>
    <country>Norway</country>
  </shipto>
  <item>
    <title>Empire Burlesque</title>
    <note>Special Edition</note>
    <quantity>1</quantity>
    <price>10.90</price>
  </item>
  <item>
    <title>Hide your heart</title>
    <quantity>1</quantity>
    <price>9.90</price>
  </item>
</shiporder>
Now we want to create a schema for the XML document "shiporder.xml"
Here is the complete listing of the schema file called "shiporder.xsd":

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderperson" type="xs:string"/>
      <xs:element name="shipto">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="address" type="xs:string"/>
            <xs:element name="city" type="xs:string"/>
            <xs:element name="country" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="item" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="note" type="xs:string" minOccurs="0"/>
            <xs:element name="quantity" type="xs:positiveInteger"/>
            <xs:element name="price" type="xs:decimal"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="orderid" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>
</xs:schema>

Difference between SAX and DOM

Both SAX and DOM are used to parse the XML document

SAX
DOM
It stands for Simple API for XML
It stands for Document Object Model
SAX is event-based 
DOM is tree model
In SAX, events are triggered when the XML is being parsed
In DOM, there are no events triggered while parsing.
Parses node by node
Stores the entire XML document into memory before processing
Doesn’t store the XML in memory
Occupies more memory
We can’t insert or delete a node
We can insert or delete nodes
Top to bottom traversing
Traverse in any direction.