14 December 2012

The MVC Programming Model in Asp.net


The MVC Programming Model in Asp.net


MVC is one of three ASP.NET programming models.
MVC is a framework for building web applications using a MVC (Model View Controller) design:

The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes:
  • Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).
  • View. The view manages the display of information.
  • Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.
    Ff649643.des_MVC_Fig01(en-us,PandP.10).gif

    It is important to note that both the view and the controller depend on the model. However, the model depends on neither the view nor the controller. This is one the key benefits of the separation. This separation allows the model to be built and tested independent of the visual presentation. The separation between view and controller is secondary in many rich-client applications, and, in fact, many user interface frameworks implement the roles as one object. In Web applications, on the other hand, the separation between view (the browser) and controller (the server-side components handling the HTTP request) is very well defined.

  • 28 November 2012

    Get only Date in Sql Server

    Get only Date in Sql Server


    convert(VARCHAR(10), Fieldname, 101) AS [Field Name]


    26 November 2012

    royalarun.blogspot.com menu

    C# and VB.Net :

    What is Dotnet Framework?

    Root namespace in dotnet framework

    What is Webservice in asp.net

    Base class for all classes in Dotnet framework

    Asp.net Page Life cycle Overview?

    Server.Transfer vs Response.Redirect

    Change File creation date and time Conversion in C#

    Bucket Problem in C# windows application

    Session state mode in asp.net

    Update Datatable in C#

    Common myths in Asp.net

    Windows Communication Foundation Overview

    WCF and Webservices

    Synclock and Lock in C#

    Lamda Expression in C#

    Anonymous type in C#

    Extension Method in C#

    String vs string in C#

    Use of Using statement in C#

    CalendarExtender show only years asp.net ajax control

    Check Connection string is valid or not in C#

    Event viewer read , write and Clear in C#

    Application path in windows application in C#

    Asp.net Path details - Absolute path and Relative path

    Use Application Wrapper Class To Access Web.Config Values

    Web application vs Web Service

    End Point, Address Binding in WCF

    Calling Javascript from server side in asp.net

    C# and VB.net Connectivity with Query string

    Debug the Windows server in Setup

    C# and Vb.net Connectivity using Stored Procedure

    Generics in Dotnet

    Boxing and Unboxing in Dotnet

    Response.redirect true vs False

    Asp.net Impersonation

    HTTP Status Code

    Session state mode in Asp.net

    Client side state management in asp.net

    Page life cycle event in asp.net

    Web application vs Website in Asp.net

    Cloud Computing Definition

    View State vs Hidden Fields in asp.net

    Adding datarelation in Datatable in C#

    Click the button when enter button is pressed in asp.net

    Naming Convention in Asp.net

    Export datatable in C# Windows application

    Calculate time Difference between two dates in Asp.net

    Webfarm in asp.net

    Webgarden in Asp.net

    When to use Generic Collection

    String is Immutable in C# and Java, Use of String builder in C#

    SqlBulk Copy in C#

    SqlHelper Class file from Microsoft in C#

    Hash table in C#

    Get Multiple Value from CheckedListbox control in C#

    List in C#

    Session vs Caching in asp.net

    Refer one asp.net page to another asp.net page

    Http modules in asp.net

    Http Handlers in asp.net

    Get the Function name,Line number,Columnnumber of the Error in C#

    What is Reflection and example

    Choose the right Generic collection type in Dotnet framework

    Difference between Assembly and Namespace in dotnet framework

    Partial Class in C#

    Why use Collections in Dotnet Framework

    Move next line in multiline textbox in C#

    Problem:Combobox Editable in C# Windows application and Asp.net
    Partial Class in C#

    Linq and XML in C#

    Connection string for C# and Vb.net

    Difference between typed dataset and untyped dataset in .Net framework

    What are the basic differences between user controls and custom controls?

    DELEGATES IN C#

    OUTPUT PARAMETER IN C#

    Advantages Of Visual Studio 2008

    Option Explicit statement and Option Strict Statement

    Difference Between Int32.Parse(), Convert.ToInt32(), and Int32.TryParse()

    E-mail Validation Using REGEX

    VB.NET VALIDATION USING ASCII

    C# VALIDATION USING ASCII


    Configuration system fail to initialize in C# windows application

    Single Click Selection - CheckListbox Change Property Double click to Single Click C# and VB.NET

    Disable remember password option in Firefox/Internet Explorer In Code

    How to Overcome multiline textbox [draggable] for mozilla firefox and Chrome Browser in asp.net

    WCF vs Webservice in asp.net

    COALESCE (Transact-SQL)


    OOPS
    Single responsibility principle in OOPS

    When to use Structure?

    When to use Delegates instead of Interface?

    When to Use Inheritance?

    Stack and Queue real time example

    Composition vs Inheritance in OOPS

    When to Use Abstract class

    When to use Interface ?

    Interface vs Abstract Class

    Single ton Class with example in C#

    Meaning For Dotnet First line of Code

    Difference Between ASP.NET Server Controls,HTML Server Controls and HTML Intrinsic Controls


    General

    What is Mobile apps?

    Difference between Sleep and Hibernate in Laptop

    Cloud computing - Overview

    Alternate tag for Html tag, while posting in blog

    To reset IIS

    Redbus Success Story

    Difference between 32 bit and 64 bit Processor

    Run Commands that can be used in both “Windows Operating System

    Difference Style of Communication

    Assertive Communication

    Link with in the page in HTML

    Sql Server Queries

    50 new features in Sql Sever 2008

    Sql Server Tips and Guidelines

    SSMS Tool Pack Free Download

    Sql Group by Function with Example

    Normalization types with example

    View in Sql Server with Example

    Get all the table name in Database Sql Server

    Delete all Stored Procedure in Sql Server

    Varchar vs nVarchar in Sql Server

    Sql Server Having Clause

    Copy one table to another in Sql Server

    Stored Procedure that change in Last n days

    Stored Procedure that create in n days in Sql Server

    Show the Stored Procedure Permission details in Sqlserver

    Query to Find Seed Values, Increment Values and Current Identity Column value of a table in Sqlserver

    Delete Column in Sql Server tables

    Script for renaming object in Sql Server

    Script for renaming table Column in Sql Server

    Select and Case statement in Sql Server

    Sql Server where 1=0

    Sql Server where 1=1

    While loop in Sql Server

    Pivot and Unpivot Query in Sql Server

    Display list of stored procedure using particular text in Sql Server

    Find the text in Stored Procedure in Sql Server

    Sql injection in Sql Server

    Hierarchy ID in Sql Server

    Try Catch in Sql Server

    Wait for in Sql Server 2008

    Trigger overview in Asp.net

    Difference between Primary key and Unique Key

    Different types of Database keys

    Difference between sp_executesql and EXEC() in Sql Server
    Microsoft SQL Server Constrains

    Uses of SET XACT_ABORT in Sql Server

    Dynamic Store Procedure in Sql Server

    Check String is null or empty in Sql Server

    Empty all table values in Sql Server

    Difference between Temporary table and Global Temporary table

    Trigger in Sql Server and types

    Difference between Oracle and Sql Server

    Difference between const and static readonly keywords C#

    SET NOCOUNT { ON | OFF } in DOT NET

    Introduction to Merge Statement – One Statement for INSERT, UPDATE, DELETE

    Insert Multiple Rows in a single statement in Sql Server 2008

    SQL PRIMARY KEY

    SQL FOREIGN KEY

    Difference between Stored procedure vs User Functions in Sql server

    Difference Between SCOPE_IDENTITY and ROWCOUNT in sql server

    Convert String to Datetime in Sql Server

    To Find Highest Salary, nth Highest Salary, Lowest Salary, nth Lowest Salary

    Coding to get nth record in sql server

    Trigger example in Sql Server

    PRIMARY KEY Constraints Primary key and Composite Primary key

    Get only Date in Sql Server



    20 November 2012

    Update Datatable in C#


    // Update Datatable in C#

    //Two methods to Update Datatable in C#

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;

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


                try
                {
                    DataTable dt = new DataTable();
                    //Add Datacolumn
                    DataColumn workCol = dt.Columns.Add("FirstName", typeof(String));

                    dt.Columns.Add("LastName", typeof(String));
                    dt.Columns.Add("Blog", typeof(String));
                    dt.Columns.Add("City", typeof(String));
                    dt.Columns.Add("Country", typeof(String));

                    //Add in the datarow
                    DataRow newRow = dt.NewRow();

                    newRow["firstname"] = "Arun";
                    newRow["lastname"] = "Prakash";
                    newRow["Blog"] = "http://royalarun.blogspot.com/";
                    newRow["city"] = "Coimbatore";
                    newRow["country"] = "India";

                    dt.Rows.Add(newRow);

       

                  // 1st method
                    // Get all DataRows where the name is the name you want.
                    IEnumerable< DataRow > rows = dt.Rows.Cast< DataRow >().Where( r => r["firstname"].ToString() == "Arun");
                    // Loop through the rows and change the name.
                    rows.ToList().ForEach(r => r.SetField("firstname", "AnotherName"));

                    // 2nd method
                    // Alternative approach.
                    // Simply loop through the rows, check the value of the Name field and change its value accordingly.
                    foreach (DataRow row in dt.Rows)
                    {
                        if (row["firstname"].ToString() == "AnotherName")
                            row.SetField("firstname", "Arun");
                    }

                }
                catch (Exception ex)
                {
                    throw ex;
                }


            }

        }
    }





    11 October 2012

    Common myths in Asp.net


    Common myths in Asp.net :

    C# code is faster than Visual Basic code:

    ·         if good programming practices are followed, there is no reason why Visual Basic and C# code cannot execute with nearly identical performance. To put it more succinctly, similar code produces similar results.

    Codebehind is faster than inline :
    ·         It doesn't matter where your code for your ASP.NET application lives, whether in a codebehind file or inline with the ASP.NET page.

    Components are faster than pages:
    ·         It is better to group functionality logically this way, but again it makes no difference with regard to performance.

    For Each is better performance than For loop:
    Really for loop has  better performance than Foreach statement





    2 October 2012

    Windows Communication Foundation - Overview


    Windows Communication Foundation - Overview
    Windows Communication Foundation (WCF) is a framework for building and running service-oriented applications. WCF unifies and extends the functionality of existing Microsoft connecting technologies, providing a single programming model independent of underlying communications protocols. WCF applications can interoperate with other technologies using open standards and protocols. 
    Characteristics and Benefits
    Windows Communication Foundation delivers the following primary benefits: service-oriented architecture (SOA) support, flexible support for messaging models, a unified programming model, protocol neutrality, increased reliability, standards-based interoperability, integrated security and messaging services, and a flexible architecture designed for extensibility.

    Service-Oriented Architecture (SOA)

    Windows Communication Foundation is based on the principles of service-oriented architecture and programming. Service-orientation is an important complement to object-orientation that applies the lessons learned from component software, message-oriented middleware, and distributed object computing. Whereas object-oriented development focuses on applications that are built from interdependent classes, service-oriented development focuses on systems that are built from a set of autonomous services. The internal implementation of each service could be object-oriented.
    Client and server applications built with WCF are composed of .NET Framework 3.0-supplied and developer-created classes. For very complex applications, an intermediate level of organization, called component architecture may also be applied, as depicted for a service in the following diagram:
    Bb756964.Top10_19(en-us,MSDN.10).gif
    A set of deployed, interacting services is called a system. SOA interactions are loosely-coupled because all communication is based upon published contracts and policies, standardized protocols, and schematized information. Contracts describe published interfaces, their operations, and the corresponding messages.

    Unified Programming Model

    Windows Communication Foundation represents the next generation connecting technology that combines and extends the best attributes of existing connecting technologies to deliver a unified development and runtime experience. It provides a single API and a consistent, straightforward programming model that supersedes the following technologies:
    • DCOM and .NET Remoting support for efficient Remote Procedure Call (RPC) functionality.
    • ASP.NET Web Services (ASMX) support for easily configurable, interoperable Web Services.
    • .NET Framework Enterprise Services support for synchronization, distributed transactions, basic security, and distributed COM+ services.
    • Web Services Enhancements (WSE) support for open Web Service standards, collectively known as WS-* specifications. This includes security, reliable messaging, and distributed transactions specifications.
    • Queued messaging that is compatible with either MSMQ or the .NET Framework System.Messaging namespace technologies.

    Flexible Support for Messaging Models

    Classical Web services typically assume a request/reply message exchange pattern, where the client issues a request message and the service responds with a reply message. This pattern is particularly suited to HTTP because it is a stateless protocol with no delivery guarantees. In contrast, Windows Communication Foundation enables a wide variety of message topology solutions.
    Two main communication state models are supported:
    • stateless model — messages are received with few or no guarantees. The stateless model is equivalent to most current-day Web services and is useful when broadcasting non-critical, one-way information.
    • stateful model — creates a communication session between two service objects. This model uses session state to enable Web services to provide advanced message functionality across the Internet, including callback methods, events, widely distributed transactions, and reliability and durability guarantees that enterprise applications require.
    Three basic message-exchange patterns are supported:
    • Datagram — one-way invocation, no response.
    • Request/reply — one way invocation with response.
    • Duplex — two-way invocation.
      Request/reply and duplex messages can be invoked synchronously or asynchronously. Each node can act as a client, service, or both.
    Windows Communication Foundation provides a variety of built-in transports and messaging protocols and supports custom transports and protocols. More complex messaging solutions (for example, publish-and-subscribe or peer-to-peer) can be built on top of these basic capabilities.

    Protocol Neutrality and Flexibility

    Windows Communication Foundation contains a set of predefined communication bindings (a binding is a set of communication characteristics including communication protocols) that will serve a wide range of common usage scenarios. However, the protocol-agnostic design of WCF supports flexibility in the following ways:
    • The messages exchanged between service and clients are defined in contracts that are independent of the protocols used to exchange those messages.
    • A single service can support multiple protocols simultaneously.
    • A pluggable communication infrastructure enables custom protocols to be defined and used in a straightforward manner.
    Protocols can be selected through both imperative code and configuration files. Typically, the developer implements the logic of an application, including default protocols and minimum requirements, and the service administrator specifies configuration details at deployment, which often include the actual protocols used. These deployment-time policies do not require recoding or recompilation, enabling the administrator to tune the deployment of the service or client.

    Reliability

    The reliability and robustness of solutions built with the Windows Communication Foundation is assured for a number of reasons, including:
    • SOA requires loosely-coupled, autonomous clients and services, which increases unit isolation; the loss or corruption of one service does not bring down the entire solution.
    • Message delivery can be assured at either the transport level or at the message level using the WS-Reliable Messaging protocol. This guarantees that messages are delivered in a consistent pattern (for example, in-order and delivered exactly once).
    • For more sophisticated requirements, queued messaging through MSMQ is supported.
    • Powerful mechanisms are available to handle critical failures; internal application exceptions and external message faults are handled in an elegant and consistent fashion.
    • Distributed transaction support increases the reliability of a solution by enforcing operation consistency and further decreasing process coupling.
    • Perhaps most importantly, WCF eliminates the need for each organization or project to develop their own messaging infrastructure, freeing them to concentrate on developing code in their area of expertise.

    Extensibility

    Windows Communication Foundation supports extensibility through the following features:
    • A thoroughly extensible object model, making it possible to customize the product to suit specific customer needs.
    • Composable protocol channels that allow combining or stacking existing protocols to satisfy scenario requirements.
    • An architecture designed to support pluggable extension classes so that the following areas can be customized: protocols, transports, behaviors, bindings, serializers, message inspectors, and validators. These types of extensions are beyond the scope of this document, but for more information, see "Extending Windows Communication Foundation" in the Windows SDK.
    From a developer's perspective, these extensibility features are both straightforward and powerful to use.

    Integration and Interoperability

    The Windows Communication Foundation assures a high level of compatibility with other Web services and existing Microsoft messaging technologies. Interoperability is often a primary concern for large scale, organization-wide solutions (for example, Enterprise Application Integration (EAI) and Business-to-Business Integration). Messaging interoperability issues fall into two categories:
    • With other messaging platforms, possibly residing on heterogeneous operating systems and programming languages
    • With other Microsoft services and messaging technologies
    From a messaging perspective, WCF is designed to be platform-agnostic. Because it uses open WS-* standards to transport, format, and interpret messages, it can interoperate with any other messaging system that relies on these same standards. Specifically, WCF services will interoperate with any system that communicates using WS-I Basic Profile (BP)-compliant wire protocols. (The Web Services Interoperability Organization (WS-I) is a consortium of leading Web service leaders whose mission is to develop and promote interoperable messaging standards.) For example, WCF interoperates with existing ASP.NET Web services (ASMX). WS-* standards for reliability, security, and transactions are also supported, which makes it interoperable with the Web Services Enhancements for .NET Framework (WSE) 3.0.
    The following diagram depicts the Web services stack and lists the primary standards supported at each level.
    Bb756964.Top10_20(en-us,MSDN.10).gif
    Microsoft has also done significant work to assure compatibility of Windows Communication Foundation with existing Microsoft technologies for building distributed systems (for example, Enterprise Services, COM+ services, and Message Queuing). Applications built with these existing technologies can now easily expose functionality as Web services. Windows Communication Foundation can communicate with these applications using standard Web service's profiles. The migration of existing applications that use .NET Remoting, ASP.NET Web services, and .NET Framework Enterprise Services to natively use the Windows Communication Foundation is often straightforward and cost-efficient. More information on specific integration approaches will be published on MSDN online.
    From a general application development standpoint, Windows Communication Foundation integrates seamlessly with other managed technologies, and through .NET interop, with unmanaged technologies.

    Integrated Security and Messaging Services

    Security is a prime consideration. Message identity, confidentiality, integrity, authentication, authorization, and auditing are provided through transport- or message-level security mechanisms.
    Security Level
    Example
    Description
    Transport
    HTTPS, SSL over TCP
    Point-to-point security that protects the entire message by encrypting the communication stream. Transport-level security schemes are widely deployed and usually more efficient than message-level security.
    Message
    WS-Security family of specifications
    End-to-end security where only message contents, or portions of them, are encrypted. Message-level security schemes are independent of transports and message-exchange patterns. Although they tend to be slower to process, they are much more flexible and extensible, and can use a variety of authentication schemes.
    Windows Communication Foundation also provides a basic level of federation, in that a service can be configured to accept security credentials from multiple authorities, possibly using different identity and authorization schemes. Other areas of security (for example, authentication, non-repudiation, auditing, and resource protection) are provided by the .NET Framework or the Windows operating system.
    In addition to basic delivery and security, a wide range of high-level message services are provided, including:
    • Metadata — WS-Policy, WS- Policy Attachments, and WS- Metadata Exchange protocols (in addition to WSDL used to describe Web services) are supported to dynamically convey service metadata.
    • Queued messaging — WCF delivers queued messaging functionality by using MSMQ as an underlying transport. Integration with an existing Message Queuing solution and the creation of a new asynchronous queue are both supported.
    • Transactions — WS-Atomic Transaction and WS-Coordination protocols are supported through the managedSystem.Transactions namespace. This service allows two or more nodes, possibly interoperating using WS-*protocols, to participate in a distributed transaction.
    • Content-based Routing — routing is enabled through support of the WS-Addressing protocol and custom WCF routers. Routing can be refined by filtering on content using the WCF filtering feature.

    1 October 2012

    Difference between WCF and Webservice in asp.net


    Difference between WCF and Webservice in asp.net

    -Webservices can be accessed only over HTTP and it works in stateless environment, WCF Service support  HTTP, TCP, IPC, and even Message Queues for communication.

    - WCF is flexible because because its services can be hosted in different types of application like [IIS,WAS,Self-hosting and Managed Windows service]

    - Webservices use XmlSerializer, But WCF uses DataContractSerializer, and it is good performance compare with XmlSerializer.

    - DataContractSerializer can translate the HashTable into XML

    - In webservice Only Public fields or Properties of .NET types can be translated into XML
    - ASP.NET web services are compiled into a class library assembly and a service file with an extension   .asmx will have the code for the service.

    -WCF Service can be hosted within IIS or WindowsActivationService.

    -In ASP.NET Web services, unhandled exceptions are returned to the client as SOAP faults.
    -In WCF Services, unhandled exceptions are not returned to clients as SOAP faults. To return SOAP faults    to clients, you can throw instances of the generic type, FaultException, using the data contract type as the    generic type.

    -Web services provides only singlex communication,but WCF Supports shalf duplex and full duplex communication.

    Half duplex

    Half-duplex data transmission means that data can be transmitted in both directions on a signal carrier, but not at the same time.
    half-duplex transmission implies a bidirectional line (one that can carry data in both directions).

    They work in an stateless fashion over HTTP and are hosted inside a web server like IIS

    Full duplex

    Full-duplex data transmission means that data can be transmitted in both directions on a signal carrier at the same time.
    Full-duplex transmission necessarily implies a bidirectional line (one that can move data in both directions).


    WCF is a replacement for all earlier web service technologies from microsoft.

    Implementing OAuth validation in a Web API

     I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...