Thoughts on .Net & Coding
.Net Articles, tutorials, reviews, code and more...
-
Using Tracing in ASP.NET Web API
While debugging an ASP.NET Web API you may need to figure out how your code is being executed and you may also want to track its execution sequence. That is where tracing comes into the picture. Using tracing you can trace the flow of execution and various events happening in the Web API. You can either use the default trace writer provided with the Web API or create your own. This article shows how both of these approaches can be used.
-
Using Custom Action Names in ASP.NET Web API
By default Web API action methods use the same HTTP method name that they are serving. For example, to deal with the HTTP GET method the Web API has the Get() action method. However, you may want to customize these action method names for the sake of better readability. There are several ways in which you can customize these action method names. This article discusses them with an example of each.
-
GridView Paging with Skip() and Take()
Paging is one of the most commonly used features of ASP.NET GridView control. ASP.NET 4.5 model binding features allow you to bind a GridView with data returned by a custom method. This method is specified using the SelectMethod property and can make use of LINQ and Entity Framework to fetch data. Additionally, it allows you to implement custom paging. This article shows how.
-
Returning Images from ASP.NET Web API
Sometimes you need to save and retrieve image data in SQL Server as a part of Web API functionality. A common approach is to save images as physical image files on the web server and then store the image URL in a SQL Server database. However, at times you need to store image data directly into a SQL Server database rather than the image URL. While dealing with the later scenario you need to read images from a database and then return this image data from your Web API. This article shows the steps involved in this process.
-
Uploading Files Using ASP.NET Web Forms, Generic Handler and jQuery
In order to upload files from the client machine to the server ASP.NET developers use FileUpload server control. The FileUpload server control essentially renders an INPUT element with its type set to file and allows you to select one or more files. The actual upload operation is performed only when the form is posted to the server. Instead of making a full page postback you can use jQuery to make an Ajax call to the server and POST the selected files to a generic handler (.ashx). The generic handler can then save the files to a specified folder. The remainder of this post shows how this can be accomplished.
-
Validating Data Using Data Annotation Attributes in ASP.NET MVC
The 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.
-
Preventing Cross Site Scripting Attacks in ASP.NET MVC 4
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 process.
-
Using Friendly URLs in ASP.NET Web Forms
Websites often 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.
-
Select, Zip and Download Files displayed in a GridView
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.
-
Tricky issue with HTML5 drag and drop
Recently a reader asked about a tricky issue with HTML5 drag and drop. The issue is this: