By Carlos MartinezDependency Injection is a form of Inversion of control where the dependent objects are injected into a class, instead of creating an instance.
The usual way to implement this pattern is using an object container and plain objects. Each container injects the entire requested objects based on a previous configuration.
A new interface is available in MVC 3, called “IDependencyResolver”. This interface enabled service location by providing these 2 methods:
· GetService(Type serviceType)
· GetServices(Type serviceType)
While in MVC 2 a custom ControllerFactory has to be created (and specified in the application class), in MVC 3 all it takes is to specify a...
By Guillermo Cedillo
Create new Project
The master page contains concepts from boilerplate. Boilerplate is an excellent template which groups the best recommendations for webpage performance (it helps you a lot to obtain an A-grade with Yslow or Google PageSpeed).
For our project I just add some features from boilerplate. I like to keep it simple but feel free to review it and implement the best concepts for your project.
Those basic concepts are:
• Add styles on the top and scripts on the bottom.
• Add ie6/ie7/ie8... class in the html tag to allow ie fixes for css.
• Add metatags for compatibility and descriptions.
• Add modernizr for a...
By Guillermo Cedillo
Yahoo provides a very useful tool to achieve this, the YUI compressor.
To set this up is very simple, you must first download the tool http://yuicompressor.codeplex.com/, and this file contains two dll's: EcmaScript.NET.modified.dll and Yahoo.Yui.Compressor.dll.
Create a folder inside your project with the name of MSBuild and put your dlls there.
Then we need to create a MSBuildCompressor.xml file where we are going to define the compressor options and the files to compress. If you want to k...
By David E.
On rare occasions inside our web application it is necessary to allow the user to enter some content in html format. In previous versions this was possible, and it was the responsibility of the programmer to validate those labels to prevent a user from entering malicious code to our application.
With ASP.net 4.0 the information will now be validated automatically. If a user tries to add html tags to a web application, the result will be an exception. This validation feature can be disabled with a simple statement of the web.config file.
The first thing to do in Visual Studio 2010 is to create a new web application, then we can add a new web form and then create the basic ...
By Alejandro Villarreal
If you’ve ever dealt with the front-end part of application development in ASP.NET, you might have encountered the following error at some point:
A potentially dangerous Request.QueryString value was detected from the client
This happens when the user submits a value (either in a form or in the query string) that the ASP.NET Framework considers dangerous, in the sense that it might be an HTML/script injection attack.
Sometimes it is necessary to turn that feature off (see here and here on how to do it). It might be the case that you expect the user to provide valid XML/HTML, and thus you don’t want the Framework to abort the request with an Exception. As explai...
By Denisse Zavala
Sharing server variables with client side scripts is nowadays a situation than can be easily overcome by choosing one of the several existing approaches.
When it comes to accessing the values stored in the .resx file the story is not different, and in this post you can find a really simple way to achieve it.
1. Add a web form to the web site, clear the markup so that only the @Page directive is present:
3. Use a ScriptManager control in the master page to register the script created:
4. Now the resources are available throughout the client scripts us...
By Guillermo Cedillo
Use Microsoft Ajax to extend you services
If you want your service works as a REST service and return JSON is not necessary to do some complex modifications in the web.config or import special libraries. When you have a WCF or an asmx web service already implemented, the easiest and cleaner way to extend your services is using the ScriptManager Control of Microsoft Ajax.
First, enable your service to work with the Script Manager add or uncomment [ScriptService] in every web service that you want to extend.
Then in your page add the Script Manager and add the reference to your services like this:
By Denisse Zavala
We all know how dealing with spam can be a real pain. However, nowadays we can rely on several tools to avoid this problem.
reCAPTCHA, a system developed by Carnegie Mellon University, provides an anti-bot service that can be embedded into web pages to protect them from automated applications trying to get access.
While all the information regarding reCAPTCHA is available in their website I will provide the steps to add a reCAPTCHA module into an ASP.NET site, using AJAX and Prototype to perform the validation.
1. Create an account and get the API keys
2. Download the library.
Add the reCAPTCHA module to the page...
By Fernando G.
First off, we need to have a quick overview of what REST means to the development community, and we can start by what does REST stands for? It stands for Representational State Transfer. Right, it did not help a lot, right?
In the SOA era, we have Service Oriented Systems interacting between them exposing Services, some applications act as consumers and some as producers. At the end, a Service Oriented Architecture allows an organization to create a well thought and organized set of libraries being used uniformly among all of the participants with no redundancy of business rules and specially having a single set of Services. Well, not always the case. It re...
“Command Timeout” is not equal to “Connection Timeout”.
A few days ago I had an application that was throwing the following error:
“Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding…”
It was an obvious error, a database timeout. I reviewed the Connection String and it didn’t have the property “Connection Timeout” (The default connection timeout is 30 seconds). So I added the property and set it to 600 seconds.
<add name="ConnectionString" connectionString="Data Source=localhost\SQLEXPRESS;Integrated Security=SSPI;Connection Timeout=600;" />