Saturday, July 18, 2015

ASP.NET MVC Controller Actions

MVC Actions usually returns instance of a class which derives from ActionResult. But you can return any type of object from MVC action even objects. These return types are wrapped in appropriate ActionResult type before they are rendered in response stream.


There are few tricky things you need to understand when dealing with HTTP methods and Controller actions. The most basic form of returning a result from controller action is like below,


The return type Json above is just an extension method which returns JsonResult. There is no difference between returning Json and JsonResult

The above ReturnJSON() and GetAction() actions cannot be called via. a GET request. You'll get the following 500 internal server error.


You can read more about that here and here. But you can use HTTP methods like POST or PUSH to successfully call the ReturnJSON action. But since GetAction() is decorated with HttpGet attribute you can't call it using POST. If you try you'll get 404 not found error. 


You can get GET request work when you do like below. Not only GET, this allows you to do POST, PUT requests as well. 

You can do the following only to allow GET requests or POST requests.

Resources

Saturday, May 9, 2015

Application Pools in IIS

Application pool is a way to manage multiple web applications under IIS server. App pools allows you to isolate applications with different security controls from one another. It helps you to manage your applications separately. 


IIS Worker Process
Is a Windows process (w3wp.exe) which runs web applications. It is responsible for handling requests for a specific application pool. App pool can contain more than one worker process. This is known as web farm or web garden. Read here

Application Pool Recycling
To make the application running smooth without memory leaks you need  to recycle the application pool. Any code which failed to implement IDisposable would run finalizers which will release resources.


Identity

Application Pool Settings (General)
  • .NET CLR Version
    • This should correspond to appropriate version of .NET framework version of your application
  • Managed Pipeline Mode
  • Queue Length
    • Max No. of requests HTTP.sys will queue for the app pool. When queue is full you'll get 503 "Service Unavailable" error
  • Start Mode : OnDemand or Always Running. See (SimpleTalk - Speeding up your application with Auto-Start feature)

Resources

Friday, May 1, 2015

LINQ in Entity Framework

To retrieve lists from database you can use IEnumerbale<T> or IQueryable<T> interfaces. IQueryable allows you to do LINQ-to-SQL while IEnumerable<T> is LINQ-to-Objects. Both gives you the opportunity to do deferred execution. (Read this article for more).

In IEnumerable all objects matching the original query will be loaded to the memory from database. 

Above first and last LINQ statements will generate first SQL query while second LINQ expression will generate the second query below,

LINQ First and FirstOrDefault


LINQ Single and SingleOrDefault


LINQ Any
Note that Count will iterate all the records in the table while Any will stop at first record it finds. (source)

LINQ Count and LongCount



The difference between Count and Count_Big is latter returns bigint while count returns int. See more details on data types.

LINQ Contains




















Group by

Saturday, February 7, 2015

Introduction to ReactJS


React is a JavaScript library developed by Facebook. ReactJS focuses on,
  • UI : Use React as the V in MVC
  • Virtual DOM : DOM diff implementation for high performance
  • Data flow : Offers reactive data flow
React is all about building reusable components. (Why Facebook built react). It doesn't manipulate DOM unless it needs to (check react displaying data example). It uses a fast, internal mock DOM to perform diffs and computes the most efficient DOM mutation for you. React components can only render a single root node. If you want to return multiple nodes they must be wrapped in a single root. Why React's Virtual DOM concept is more efficient than dirty model checking. Also check how Virtual DOM and diffing works in React.

Why use Reactjs


Here's a simple hello world example. Here, React.createClass will create a Component. (Read more)

var App = React.createClass({
            render: function () {
                return React.DOM.h1(null, "Hi there");
            }
        });
React.render(App(), document.body);

JSX

React believes components are the right way to separate concerns rather than using templates. JSX enables you to create JavaScript objects using HTML syntax.

const element = <h1>Hello, world!</h1>;

JSX is similar to HTML, but not exactly the same. See JSX Gotchas and JSX in depth. You don't have to use JSX with React. You can just use plain JS. However, we recommend using JSX because it is a concise and familiar syntax for defining tree structures with attributes.

JSX elements gets converted to react elements with Babel. Same as what you create using React.createElement method. Therefore you can only have single root tag for a JSX statement.

React can either render HTML tags (strings) or React components (classes). React JSX transforms from an XML-like syntax into native JavaScript. 


Components and Props

Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.

Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

Loading Ajax data using JQuery

In Load Initial Data via AJAX example, you can see how to load data from ajax call and show them in the browser. We use JQuery here to make things easier. Typical error you'll get when implementing is mountNode is not defined error.

React integration with C# and ASP.NET MVC

You can use ReactJS.NET to integrate your .NET application easily. Take a look at this sample tutorial.



What is Flux

Architecture Facebook uses internally when working with react. It is now recommended to use Redux over Flux

https://scotch.io/tutorials/getting-to-know-flux-the-react-js-architecture
http://facebook.github.io/flux/docs/overview.html
http://facebook.github.io/flux/
https://www.youtube.com/watch?list=PLb0IAmt7-GS188xDYE-u1ShQmFFGbrk0v&t=621&v=nYkdrAPrdcw


Why use Redux

Redux has many benefits. Simply Redux is a state management tool. It is a very lightweight library which can be used with many JavaScript frameworks. 

Simply Redux keeps state of your application in a store. Each component can access any state that is needed from the store. So why use Redux? As React is based on components, these needs to communicate with each other. Redux helps you by keeping it in a central location. 

Redux has three building parts: actions, store and reducers.
  • Actions are events: They are the only way you can send data from your application to your Redux store. The data can be from user interactions, API calls or even form submission.
  • Reducers: Reducers are pure functions that take the current state of an application, perform an action and returns a new state.
  • Store: The store holds the application state. There is only one store in any Redux application.
Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook