data entered by the end user in various form fields must be validated
before it is saved in the database. Developers often use validation HTML
helpers provided by ASP.NET MVC to perform the input validations.
Additionally, you can also use data annotation attributes from the
System.ComponentModel.DataAnnotations namespace to perform validations
at the model level. Data annotation attributes are attached to the
properties of the model class and enforce some validation criteria. They
are capable of performing validation on the server side as well as on
the client side. This article discusses the basics of using these
attributes in an ASP.NET MVC application.
A website is
exposed to various types of attacks and one of the most common types of
attack is what is known as Cross Site Scripting (XSS). In a cross site
scripting attack, malicious markup and script is entered in the web
pages that are viewed by other users. If proper care is not taken to
filter this malicious piece of markup, the script gets stored in the
system and also rendered on web pages. Depending on the script injected
by the hacker it can cause damage ranging from annoying popups to stolen
credentials to accessing data stored in cookies. Therefore, it is
important for ASP.NET MVC developers to prevent these types of attacks.
Luckily, ASP.NET MVC offers a helping hand in safeguarding your
websites. This article discusses some of the basics involved in the
need to generate SEO friendly URLs. In ASP.NET Web Forms applications, a
URL is tied to a physical .aspx file. This default mapping between a
URL and physical file makes it difficult for Web Forms applications to
generate SEO friendly URLs. One option available to ASP.NET developers
is to use URL routing features. Alternatively they can also use Friendly
Urls - a feature that allows you to quickly and easily use SEO friendly
URLs in Web Forms applications. This article discusses how.
Sometime back I
wrote an article that shows how to zip and unzip files programmatically
using System.IO.Compression classes. Using these classes along with
ASP.NET controls you can allow user user to select one or more files
from a list and then programmatically "bundle" these files into a ZIP
archive. This short post shows how.
Recently a reader asked about a tricky issue with HTML5 drag and drop. The
issue is this:
native drag and drop through draggable property and several events such
as dragstart, drag, dragenter, dragleave, dragover and drop. Normally
dragstart event handler is where you set the data that is to be
transferred between the drag source and drop target. The drop event
handler is where you handle the drop of a drag source, access the data
transferred and process it further. Now, in this particular case only
the dragstart and drop events were handled. And the drop event handler
never used to get called. In other words dragging operation was
successful but dropping operation was not.
reasons browsers prohibit AJAX calls to resources residing outside the
current origin. This means you under the current settings, you can't
provide a service exposed by a Web API to some other origin. However, at
times you might want to allow a legitimate origin to access a resource.
This is where Cross Origin Resource Sharing (CORS) specifications come
into the picture. While there are other ways to enable CORS at the web
application level, the ASP.NET Web API takes CORS support a step further
through certain attributes. Using these attribute you can fine tune
CORS at the global level, controller level or individual action level.
This article discusses how this support can be used in your
Most of us deal
with Zip files on a daily basis. Normally people use some third-party
utility to create, open and extract Zip files. At times you may want to
deal with Zip files programmatically. Luckily, .NET framework 4.5
introduces some new classes in System.IO.Compression namespace that
allows you to do just that. Using these classes you can create new Zip
files, open and modify existing Zip files and extract the contents of
Zip files via code. This article examines some of these classes.
Basics of using arrays in C#:
frequently used to store data of the same type. You can use arrays in C#
in many different ways. Although single dimensional arrays are most
commonly used, other varieties such as multidimensional arrays and
jagged arrays are also available to C# developers. Additionally, the
Array class comes in handy when it comes to sorting or searching an
array. This article discusses all these types of arrays with examples of
jQuery) by default the data is returned in JSON format. However, in
certain cases you lay want to retrieve the data in XML format instead of
JSON. On the server side, Web API determinses what data format to use
for sending data to the client by doing what is known as Content
Negotiation. Simply put, content negotiation is a process by which Web
API inspects the incoming request and HTTP headers accompanying the
request to figure out what response format(s) the client can understand.
Based on this checking Web API sends the output.
directives are commands that are meant for the C# compiler. Using
preprocessor directives you instruct the C# compiler to alter the
compilation process in some way. For example you may instruct the C#
compiler that a particular block of code be excluded from the
compilation process. This article examines several C# preprocessor
directives available, with an example of each.