Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Thoughts on .Net & Coding

.Net Articles, tutorials, reviews, code and more...

  • Convert XML data to JSON and return it from Web API

    Recently I stumbled upon a situation where a large number of XML documents needed to be returned from ASP.NET Web API. This sounds like a straightforward task but there was a small twist to the story. The XML documents existed as physical disk files. The Web API should read these files and convert the XML data into JSON. This was needed because the client applications were designed to handle only JSON format. Here I discuss a quick way to accomplish this task.

  • Accept / Reject File Upload Depending Upon XML Schema Validation

    Uploading files from the client machine onto the server is a fairly common task in web applications. Recently I came across such an application where the end users are required to upload XML files from their machine onto the server. These XML files were produced as a result of some export operation of a desktop application installed on their machines. These XML files then used to get imported in some central database for further processing.  Uploading the file is a quite straightforward thing but in this case it was also required to validate these uploaded files against an XML schema (XSD). This was a safeguard against manual or accidental tampering of the files that might take place at the end user's side. If a file is found to be invalid the it shouldn't be accepted in the system for obvious reason. This article discusses a simple solution to accomplish this task.

  • Integrate reCaptcha V2 in ASP.NET Applications (Web Forms / MVC / Core)

    If you are running any website that makes use of Google's reCAPTCHA for keeping bots and automated scripts away, you are probably aware that version 1.0 is being phased out. That means you need to integrate version 2.0 into your websites. To that end this article explains how to do just that. I use ASP.NET MVC project to illustrate the integration process but the same applies even for ASP.NET Web Forms and ASP.NET Core applications.

  • Prepare ASP.NET projects (Web Forms / MVC / Core) to use Angular 4

    As as ASP.NET developer working with latest trends you might want to use Angular 4 in your projects. Unlike libraries such as jQuery, Angular 4 is a framework and there are quite a few steps involved before you actually start utilizing its powerful features. To that end this article explains the steps necessary to prepare your ASP.NET projects to use Angular 4. We will discuss the process for all the three flavors of ASP.NET available today - ASP.NET Web Forms, ASP.NET MVC and ASP.NET Core.

  • Use XML Data Format In ASP.NET Web API

    Modern web application use JSON as the preferred data format for the sake of transferring data between a Web API and its client. However, at times you may want to use XML data format instead of JSON. Although the overall process to accomplish this task is same, there are certain subtle but important differences. To that end this article shows how XML data exchange can be done between an ASP.NET Web API and a jQuery driven client.

  • Encode HTML, JavaScript, and URL Query Strings In ASP.NET Core

    When a web page accepts an input from the end user it can also include malicious data consisting of special characters, HTML tags, JavaScript code and the things like that. As a safety measure you should encode such data before displaying it back on to a page or while passing through URL query strings. To that end ASP.NET Core providers three encoder classes that help you accomplish just that. This article discuses how these classes can be used to encode HTML markup, JavaScript code and URL query strings.

  • Prevent Cross-Site Request Forgery In ASP.NET Core

    If you worked with ASP.NET MVC applications before, you are probably aware of Cross-site request forgery (CSRF / XSRF) attacks. You might have also used anti-forgery token based approach to prevent them. ASP.NET Core uses a similar approach but there are a few differences that you should be aware of. To that end this article briefly discusses the CSRF attack and ASP.NET Core way to prevent them.