Thursday, 14 May 2015

Don’t use Delete Links because they create Security Holes

Suppose someone sends an email to you that contains an image. The image could be embedded in the message with the following tag:

<img src=”http://www.theApp.com/Home/Delete/23” _fcksavedurl=””http://www.theApp.com/Home/Delete/23”” />

Notice that the src attribute points at the Delete() method of the Home controller class. Opening the email (and allowing images in your email client) will delete record 23 without warning. This is bad. This is a security hole.

So The Preffered way to delete in MVC is :

Examine the Delete and DeleteConfirmed methods


















The HttpPost method that deletes the data is named DeleteConfirmed to give the HTTP POST method a unique signature or name.

The common language runtime (CLR) requires overloaded methods to have a unique parameter signature (same method name but different list of parameters). However, here you need two Delete methods -- one for GET and one for POST -- that both have the same parameter signature. (They both need to accept a single integer as a parameter.)

To sort this out, you can do a couple of things. One is to give the methods different names. That's what the scaffolding mechanism did in the preceding example. Add the ActionName("Delete") attribute to the DeleteConfirmed method. This effectively performs mapping for the routing system so that a URL that includes /Delete/ for a POST request will find the DeleteConfirmed method.

---------------------------------

Another common way to avoid a problem with methods that have identical names and signatures is to artificially change the signature of the POST method to include an unused parameter. For example, some developers add a parameter type FormCollection that is passed to the POST method, and then simply don't use the parameter:














---------------------That's it.. Thanks for reading my blog.------------------------
ENGOY



TPL VS Threads

To demonstrate we have two similar program one uses Threads and other Parallel. We will not deep dive into it but we will have a clear idea How Parallel and Threads works so to make programs get's faster and optimized.

Thread uses Single Core at one time.
Parallel uses Multi Core at one time.












Now let's prove this
Thread Program
Perfmon status for the above program
Parallel Program
Perfmon status for the above program
------------------------------x-x-x------------------------------


Enjoy one of my fav song. ;)

Task Parallel Library VS Async and Await

TPL - The Task Parallel Library was designed for parallel programming.
AA Async and await are for asynchronous programming.

TPL when you have a lot of work to do and want to split up that work among multiple threads so you can use all the CPU cores.
AA when you have an operation (or many operations) that will complete in the future, and you want to do other things in the meantime.

TPL - Best suited for CPU-intensive work.
AA Best suited for I/O-bound work.

There is some overlap. For example, you can treat a parallel computation as an asynchronous operation so it doesn't tie up your UI thread. Also, both the TPL and async/await make use of the Task type, though they use it in very different ways.