Posts

Showing posts from 2015

Preventing Cross-Site Request Forgery (CSRF) Attacks in ASP.NET Web API

Cross-Site Request Forgery (CSRF) is an attack where a malicious site sends a request to a vulnerable site where the user is currently logged in Here is an example of a CSRF attack: A user logs into www.example.com, using forms authentication. The server authenticates the user. The response from the server includes an authentication cookie. Without logging out, the user visits a malicious web site. This malicious site contains the following HTML form: <h1> You Are a Winner! </h1> <form action = "http://example.com/api/account" method = "post" > <input type = "hidden" name = "Transaction" value = "withdraw" /> <input type = "hidden" name = "Amount" value = "1000000" /> <input type = "submit" value = "Click Me" /> </form> Notice that the form action posts to the vulnerable site, not to the malicious site...

Executing PowerShell scripts from C#

Image
Please refer the original post from here http://blogs.msdn.com/b/kebab/archive/2014/04/28/executing-powershell-scripts-from-c.aspx I n today’s post, I will demonstrate the basics of how to execute PowerShell scripts and code from within a C#/.NET applications. I will walk through how to setup your project prerequisites, populate the pipeline with script code and parameters, perform synchronous and asynchronous execution, capture output, and leverage shared namespaces. Update 8/7/2014 : Here is the downloadable solution file. Update 11/5/2014 : Added a section on execution policy behavior. Prerequisites: First, ensure that PowerShell 2.0 or later is installed on the system you are developing on. The features used below will not be supported on PowerShell 1.0. Next, start by making a new console application (targeting .NET 4.0) in Visual Studio. In the solution explorer, add a project reference to the System.Management.Automation assembly * . On my machine (PowerShe...

How to create custom attribute in web.config

1. Add a class file in AppCode with any name and add the following code -------------------------------------------------------------------------- public class FeedElement : ConfigurationElement {     [ConfigurationProperty("Key", IsKey = true, IsRequired = true)]     public string Key     {         get { return (string)this["Key"]; }         set { this["Key"] = value; }     }     [ConfigurationProperty("Value", IsKey = true, IsRequired = true)]     public string Value     {         get { return (string)this["Value"]; }         set { this["Value"] = value; }     } } [ConfigurationCollection(typeof(FeedElement))] public class FeedElementCollection : ConfigurationElementCollection {     protected override Configura...

Insert results of a Stored Procedure into a Temporary Table

REATE PROC getBusinessLineHistory AS BEGIN SELECT * FROM sys . databases END GO sp_configure 'Show Advanced Options' , 1 GO RECONFIGURE GO sp_configure 'Ad Hoc Distributed Queries' , 1 GO RECONFIGURE GO SELECT * INTO # MyTempTable FROM OPENROWSET ( 'SQLNCLI' , 'Server=(local)\SQL2008;Trusted_Connection=yes;' , 'EXEC getBusinessLineHistory' ) SELECT * FROM # MyTempTable

What is Abstraction?

Abstraction is a process of hiding the implementation details and displaying the essential features. Example1 : A Laptop consists of many things such as processor, motherboard, RAM, keyboard, LCD screen, wireless antenna, web camera, usb ports, battery, speakers etc. To use it, you don't need to know how internally LCD screens, keyboard, web camera, battery, wireless antenna, speaker’s works.  You just need to know how to operate the laptop by switching it on. Think about if you would have to call to the engineer who knows all internal details of the laptop before operating it. This would have highly expensive as well as not easy to use everywhere by everyone. So here the Laptop is an object that is designed to hide its complexity. How to abstract: - By using Access Specifiers .Net has five access Specifiers Public -- Accessible outside the class through object reference. Private -- Accessible inside the class only through member functi...

How to use jQuery to switch between a plus and minus sign on collapse and expand?

1. Add Jquery script ignore if already added <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> 2. Add Javascript to show hide  <script type="text/javascript">            $(".question").click(function () {             if ($(this).next(".answer").is(":hidden")) {                 $(this).next(".answer").slideDown("slow");                 $(this).children('span').text('-');             } else {                 $(this).next(".answer").slideUp("slow");                 $(this)...