This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Me And My Respected Teacher Mr Kamal Sheel Mishra

Mr. K.S. Mishra is HOD of Computer Science from SMS Varanasi where I have completed my MCA

Me And My Respected Teacher Mr Udayan Maiti

Mr. Udayan Maiti is a senior .Net Expert and has guided many professionals of multi national Companies(MNC)

Me And My Best Friend Mr Ravinder Goel

Mr. Ravinder Goel is a senior Software Engineer and now he is working Wipro Technology

Friday, 17 August 2012

How to use Web Security in Asp.net

                                                  How to use Web Security in Asp.net

Authentication: 

Authentication is any process by which a system verifies the identity of a User who wishes to access it. Since Access Control is normally based on the identity of the User who requests access to a resource, it is essential to effective Security.
It may be implemented using Credentials, each of which is composed of a User ID and Password. Alternately, Authentication may be implemented with Smart Cards,

  Means:  identified user valid or not

Authorization: 

Authorization is the process of giving someone permission to do or have something. In multi-user computer systems, a system administrator defines for the system which users are allowed access to the system and what privileges of use (such as access to which file directories, hours of access, amount of allocated storage space, and so forth). Assuming that someone has logged in to a computer.
                                            operating system  or  application the  system or application 
may want to identify what resources the  user can be given during and  session thus authorization is  sometimes seen as both the preliminary setting up of permission by a system administrator and  actual checking of the permission values that have been set up when a user is  getting access

Means:  this resources which are permission or not



Types of Security in Asp.net:  

                           · Windows based Security  (user  based)
                           ·  From based Security        (Internet based)
                   ·  Passport based Security    



There are three ways of doing authentication and authorization in ASP.NET:-

• Windows authentication: -

 In this methodology ASP.NET web pages will use local windows users and groups to authenticate and authorize resources.

• Forms Authentication: - 

This is a cookie based authentication where username and password are stored on client machines as cookie files or they are sent through URL for every request. Form-based authentication presents the user with an HTML-based Web page that prompts the user for credentials.

• Passport authentication :- 

Passport authentication is based on the passport website provided
by the Microsoft .So when user logins with credentials it will be reached to the passport website ( i.e. hotmail,devhood,windows live etc) where authentication will happen. If Authentication is successful it will return a token to your website.

• Anonymous access: -

 If you do not want any kind of authentication then you will go for Anonymous access.

Generic Principal and Generic Identity objects represent users who have been authenticated using Forms authentication or other custom authentication mechanisms. With these objects, the role list is obtained in a custom manner, typically from a database.
Forms Identity and Passport Identity objects represent users who have been authenticated with Forms and Passport authentication respectively.


                                               Process ................................................
                                     






Coding for Login.aspx.cs ………………………………………



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//using this  name  space  for  web security

using System.Web.Security;

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

    }
    protected void BLogin_Click(object sender, EventArgs e)
    {
        if (txtusername.Text == "KushKumarTiwari" && txtpassword.Text == "1234")
        {
            //FormsAuthentication.RedirectFromLoginPage(txtusername.Text, false);

            FormsAuthentication.RedirectFromLoginPage("a", false);

            Response.Redirect("WelComeUser.aspx");
           
          
        }


    }
}
 

Coding for web.config ………………………………………




<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="Login.aspx" defaultUrl="WelComeUser.aspx">
      </forms>
    </authentication>

    <authorization>
      <deny users="?"/>
    </authorization>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
 
 
  <!--this code for which part of website you want to free on your websits-->
 
  <location path="img">
    <system.web>
      <authorization>
        <allow users="*"/>
        </authorization>
    </system.web>
  
  </location>
</configuration>




Coding for Logout Button………………………………………


protected void BLogout_Click(object sender, EventArgs e)
    {
      
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
       
    }

Thursday, 16 August 2012

Using Group By keyword in LINQ to Sql



Using Group By keyword in LINQ to Sql   


Frist  we  create a table TotalItem  in DataBase ForLinq
use ForLinq
Create table TotalItem(Id int,Item int)

insert record in table TotalItem  in DataBase ForLinq

insert  into TotalItem values(3,65)

select record table TotalItem  in DataBase ForLinq

select * from TotalItem

using  group by in table TotalItem  in DataBase ForLinq

select id ,Sum(item) as TotalItem from TotalItem group by id



How  to  use  above Concept  in LINQ (Linq  to Sql)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
   //Create object for dbml class

    DataClassesDataContext dd = new DataClassesDataContext();

    protected void BGroup_Click(object sender, EventArgs e)
    {
        var v = from m in dd.TotalItems
                group m by m.Id  into g
                select new
                {
                    id = g.Key,TotalItem = (from w in g select w.Item).Sum()

                };
//Result  display  in  a  GridView  which name  is  GridView1

        GridView1.DataSource = v;
        GridView1.DataBind();


   //Result  display  in  a  Label  tabular  from  which name  is  Label2

        Label2.Text = "<table style='background-color:red;border:5px solid #CCC;'> <tr><td style='color:green;'>Id</td> <td style='color:green;'>Total</td></tr>";
        foreach (var v1 in v)
        {
            Label2.Text += "<tr><td> " + v1.id.ToString() + "</td><td>" + v1.TotalItem.ToString() + "</td></tr>";
        }
        Label2.Text += "</table>";

}
}






Monday, 13 August 2012

What is LINQ ( Insert,Delete,Update,Select,StartWith,EndWith,Contains Keyword using dbml class)


What is Linq:

 Linq  stand  for  Language Integrated Query (LINQ) is  new component of .NET Framework 3.5. LINQ is the most important new feature of C#.The basic function of Linq is to add native  data  querying capabilities to .NET Framework using syntax similar to SQL .It  is a  provider like for JDBC /ODBC for Java…………….



Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. Visual Studio includes LINQ provider assemblies that enable the use of LINQ with .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents.

 Version of LINQ:

o    LINQ to Object
o    LINQ  to  Entity
o    LINQ  to Sql
o    LINQ to Dataset
o    LINQ  to XML


           How  to  used ....................................................LINQ  to SQL


Frist we  create  Database  which name is   ForLinq

Create DataBase ForLinq
                          
After than  we create table  Student  in  Databae ForLinq

use ForLinq

create table Student(Srno int primary key identity(1,1),Name nvarchar(50),FatherName nvarchar(50),Age int,Gender nvarchar(50),Address nvarchar(200))



then we take a Webpage  for  connectivity with data base  using Linq………………….(Linq to Sql).then after  we  take  dbml classes  in our  website …………..


after  taking the dbml class the  dbml class goes to App_Code  folder in Website



dbml class divides itself in two panes  in the first pane  we  drag and  drop the tables and second  pane is used to  put  the  function and  store procedure  ,in the  dbml class we  drag the  tables from Server Explorer  






after than we  create code  in Default.cs  page…………………….



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// using  this  namespace  for  linq  connectivity
using System.Linq;


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

//  create  object for  dbml  class ……………………………………

    DataClassesDataContext dd = new DataClassesDataContext();


//Codinng for  save  data  in Table Student…………………………………

    protected void BInsert_Click(object sender, EventArgs e)
    {

        Student t = new Student
        {
            Name = txtName.Text,
            FatherName = txtFatherName.Text,
            Age = Convert.ToInt32(txtAge.Text),
            Gender = RbGender.SelectedValue,
            Address = txtAddress.Text
        };

        dd.Students.InsertOnSubmit(t);
        dd.SubmitChanges();
        LMessage.Visible = true;
        LMessage.Text = "Add Successfully";
    }
   


//Codinng for  select all  data  from Table Student and show in Gridview………………………………

    protected void BSelect_Click(object sender, EventArgs e)
    {
        var v = from m in dd.Students select m;
        GridView1.DataSource = v;
        GridView1.DataBind();
    }


//Codinng for  delete  data  from Table Student by  SrNo…………which is  primary key in table

    protected void BDelete_Click(object sender, EventArgs e)
    {
        var v = from m in dd.Students where m.Srno == Convert.ToInt32(txtSrNo.Text) select m;
        if (v != null)
        {

            dd.Students.DeleteAllOnSubmit(v);
            dd.SubmitChanges();
        }
        LMessage.Visible = true;
        LMessage.Text = "Delete Successfully";
    }


//Codinng for  update  data  from Table Student by  SrNo…………which is  primary key in table

    protected void Bupdate_Click(object sender, EventArgs e)
    {
        var v =( from m in dd.Students where m.Srno == Convert.ToInt32(txtSrNo.Text) select m).FirstOrDefault();
        if(v!=null)

        {

            v.Name = txtName.Text;
            v.FatherName=txtFatherName.Text;
            v.Age = Convert.ToInt32(txtAge.Text);
            v.Gender = RbGender.SelectedValue;
            v.Address = txtAddress.Text;

           }
        dd.SubmitChanges();

        LMessage.Visible = true;
        LMessage.Text = "Update Data Successfully";

    }

//Codinng for  select  data  from Table Student by  SrNo…………which is  primary key in table and  data show  it own textbox……………………….

    protected void BselectByid_Click(object sender, EventArgs e)
    {
        var v = ( from m in dd.Students where m.Srno == Convert.ToInt32(txtSrNo.Text) select m).FirstOrDefault();
        if(v!= null)
        {
            txtName.Text = v.Name;
            txtFatherName.Text = v.FatherName;
            txtAge.Text = v.Age.ToString();
            txtAddress.Text = v.Address;



        }
    }
}

 Then  after  we  can insert ,delete,update, retrieve record  fro table


 For Insert  data…………………….



For select Data from Table






   if  you  want  to use  Like query   in  LINQ then  it  will replace  by  some  keyword

            1.   StartWith
            2.   EndWith
            3.   Contains

//Codinng for  select  data  from Table Student by  Name…………which is  StartWith ....

protected void BStartWith_Click(object sender, EventArgs e)
    {
        var v = from m in dd.Students where m.Name.StartsWith(txtserch.Text) select m;
        GridView1.DataSource = v;
        GridView1.DataBind();

               
    
    }

//Codinng for  select  data  from Table Student by  Name…………which is  EndWith.......
    protected void BEndWith_Click(object sender, EventArgs e)
    {
        var v = from m in dd.Students where m.Name.EndsWith(txtserch.Text) select m;
        GridView1.DataSource = v;
        GridView1.DataBind();

    }


//Codinng for  select  data  from Table Student by  Name…………which is  Contains.......

    protected void BContains_Click(object sender, EventArgs e)
    {

        var v = from m in dd.Students where m.Name.Contains(txtserch.Text) select m;
        GridView1.DataSource = v;
        GridView1.DataBind();
    }





Using Group By keyword in LINQ to Sql

How to use sql function with Linq to Sql

How to execute Sql Raw Query in Linq C# .Net

Basics of LINQ Join with Lamda Expressions(Inner Join with Linq)

Left Right Full Outer Join and Cross join with Linq to Sql

Connectivity Linq with Sql Server 2008 without dbml context