ASP.NET Web Forms

Incrementally Migrating an ASP.NET Framework application to Razor Pages

calendar_today 01 September 2022 07:08

ASP.NET MVC ASP.NET Web Forms ASP.NET Core Razor Pages .NET 6

Do you have a huge .NET framework application (Web forms, MVC) that relies on authentication and/or System.Web types that you would ideally like to migrate to .NET Core, but just don't have the bandwidth to put everything on hold while you rewrite the entire application on a new framework? If so, you might be interested in an exciting new project from Microsoft - SystemWebAdapters for ASP.NET Core - that enables you to incrementally migrate your old application, endpoint by endpoint.

Free SSL Certificates On IIS With LetsEncrypt

calendar_today 02 February 2017 07:44


If you have forms on your site that take a user's personal details, you should protect the page by running it under HTTPS. That way, any data that's posted from the form (email address, credit card number etc) is encrypted and hidden from prying eyes. It's not just e-commerce sites that should be protected. Intranets and other line of business apps that require authentication, blogs with comment forms that ask for email addresses and so on. The main barrier to this in the past has been the cost of the digital certificate (SSL Certificate) that asserts that you are who you say you are. LetsEncrypt is a free, automated, and open Certificate Authority that removes this barrier.

The Best Way To Import Data From Excel To SQL Server via ASP.NET

calendar_today 14 April 2016 13:42


I've seen a lot of questions about the best way to import data from uploaded Excel files to a SQL Server database in an ASP.NET application. Most solutions involve the use of the JET or ACE OLEDB providers to read data from the saved Excel file, and some even show how to use Office Interop to obtain the data. However, all of these solutions rely on additional components being installed on the server, and they also require the uploaded file to be saved somewhere, even temporarily, which creates an additional maintenance task. The solution that follows makes use of a Nuget package that gets deployed with your application and can work with streams, so the uploaded file doesn't need to be saved. It is, in my submission, THE best way to import data from uploaded Excel files to SQL Server in an ASP.NET application.

Exploring Prefix: A Free ASP.NET Profiling Tool

calendar_today 30 March 2016 19:21


Prefix is a free profiler for ASP.NET applications. It's dead easy to use and it will help you find bugs in your code that you didn't even know you had. I found two in what I thought were properly working apps within an hour of downloading Prefix.

Request.Form Is Empty When Posting To ASPX Page

calendar_today 26 January 2016 07:39

ASP.NET Web Forms

A couple of threads have been posted recently to the ASP.NET forums complaining that values posted to ASPX files are mysteriously disappearing. This post looks at the most likely cause and provides some solutions.

SEO For ASP.NET Web Sites: Getting content indexed

calendar_today 16 December 2015 07:37


This is the last in a series of articles that explore how to optimise ASP.NET web sites for search engines. Each article in the series concentrates on a specific topic and looks at the features and tools available to ASP.NET developers to help make sites search engine friendly and thereby improve rankings and click throughs from search results. This article explores how to ensure that search engines are aware of all of the content you want them to crawl and how to inform them when the location of that content is no longer valid.

SEO For ASP.NET Web Sites: URLs

calendar_today 07 December 2015 08:57


This is the second in a series of articles that explore how to optimise ASP.NET web sites for search engines. Each article in the series concentrates on a specific topic and looks at the features and tools available to ASP.NET developers to help make sites search engine friendly and thereby improve rankings and click throughs from search results. This article will looks at some best practices concerning your site's URLs and how to make them more user friendly for search engines and humans alike.

SEO For ASP.NET Web Sites: Content

calendar_today 01 December 2015 07:53


This is the first in a series of articles that explore how to optimise ASP.NET web sites for search engines. Each article in the series concentrates on a specific topic and looks at the features and tools available to ASP.NET developers to help make sites search engine friendly and thereby improve rankings and click-throughs from search results. This first article will look at how to present your site content to search engines in the most optimal way.

Downloading multiple files in ASP.NET

calendar_today 09 October 2015 08:53


This short article examines the baffling issue that a lot of people seem to encounter when attempting to send multiple files to the client from an ASP.NET application, and provides the solution.

Reading Text-based Files In ASP.NET

calendar_today 17 July 2015 13:43

C# General ASP.NET MVC ASP.NET Web Forms

Every time I need to work with the contents of text-based files in an ASP.NET application I invariably start off thinking about using the various static methods on the System.IO.File class to extract the text and then some string manipulation or Regex to parse the content into some kind of structure. And, just in time, I remember the TextFieldParser class that hides itself away in the Microsoft.VisualBasic assembly. The purpose of this article is to introduce this component to a wider audience, but also to serve me as an aide-mémoire in terms of the basic usage, which I always have to look up.

A Better Way To Export Gridviews To Excel

calendar_today 07 July 2015 13:49

ASP.NET Web Forms EPPlus

There are countless articles that demonstrate exporting ASP.NET GridViews to Excel. They pretty much all do the same thing - they use the RenderControl method to generate HTML and then save it to a file with a .xls extension. This kind of works, but the resulting file is actually an HTML file masquerading as an Excel file. And that has two flaws: it cannot be used as a data source because providers complain that it is not in an acceptable format, and users of Office 2007 or newer are always confronted with a warning about the contents of the file when they try to open it, causing confusion, suspicion or annoyance. This article shows how to use the free, open source library to export the content of a GridView control to a genuine .xlsx file that doesn't suffer these problems.

Reading Excel Files Without Saving To Disk In ASP.NET

calendar_today 30 June 2015 14:47

ASP.NET Web Forms EPPlus

This article allows me the opportunity to demonstrate a feature of my newest favourite open source library: EPPlus. EPPlus is a .net library that reads and writes Excel 2007+ files using the Open Office Xml format (xlsx). This fantastic, easy to use (and free) library enables the use of Excel in ASP.NET applications without the need to install the Access Database Engine (ACE) or having to mess about with unsupported Office Automation on the web server (assuming you can even get Office installed there). Prompted by a rash of similar questions that appeared on the ASP.NET forums recently, this article looks at reading the contents of an uploaded Excel file without saving it, and displaying the data in a Web Forms GridView.

Scheduled Tasks In ASP.NET With Quartz.Net

calendar_today 07 August 2014 08:34

General ASP.NET MVC ASP.NET Web Forms ASP.NET Web Pages

A perennial question on the ASP.NET forums concerns how to schedule regular tasks as part of a web application. Typically, the requirement is to send emails once every 24 hours at a particular time each day, but it could actually be anything from tweeting on a schedule to performing maintenance tasks. Equally typically, half a dozen members on the forum dive in with recommendations to install Windows Services or schedule batch files with the Task Scheduler - regardless of the fact that most web site owners are not afforded such privileges as part of their shared hosting plan.

Classic ASP Include Files in ASP.NET

calendar_today 23 June 2010 07:43

Classic ASP ASP.NET Web Forms

Include files within classic ASP are about the only way to achieve some measure of code-reuse within frameworks that offer little or nothing by way of composition or inheritance. Judging by the number of questions in forums, there are still a lot of people moving across from classic ASP who are puzzled as to how to approach replacing include files within ASP.NET. A number of articles illustrate individually how to do so for site-wide layout reasons, including widgets, reusing global functions, or actually including the content of a file. However, I haven't been able to find one resource that brings all these together, hence the purpose of this article.

Highlighting Keywords Found In Search Results

calendar_today 22 May 2010 19:41

C# ASP.NET 3.5 Extension Method ASP.NET Web Forms

A common question in the forums is how to highlight key words found in search results. Here's an extension method that does that, both for partial matches, or whole word matches.

Storing Files and Images in Access with ASP.NET

calendar_today 06 December 2009 19:46

MS Access ASP.NET 3.5 ASP.NET Web Forms

Should you store files and images in the database or the filesystem in an ASP.NET application?  With SQL Server this is a dilemma, with both approaches having their pros and cons.  When it comes to Access, the decision is much easier to make.  Because an Access database is restricted to 2Gb, it makes more sense to store files in the file system.  However, sometimes, you may not have the choice. If you have to use the database, here's how.

Simple File Download Protection with ASP.NET

calendar_today 25 November 2009 09:09

ASP.NET 3.5 ASP.NET Web Forms

When it comes to protecting files from unauthorised downloading, the vast majority of articles offer solutions that involve mapping common file types (.pdf, .txt, .doc etc) to ASP.NET within Internet Information Services.  However, often in a shared hosting environment, you don't have access to IIS and the hosting company will not agree to providing such mappings for you, so what do you do?

Handling JSON Arrays returned from ASP.NET Web Services with jQuery

calendar_today 10 January 2009 09:09

AJAX Javascript ASP.NET 3.5 jQuery ASP.NET Web Forms

There appear to be many articles showing how to use jQuery with ASP.NET Web Services around, but the vast majority of them illustrate the use of PageMethods that return a single value - typically "Hello World!" or the current date and time. Not much use in the real world, where you may more often need to call a service that returns a collection of complex objects. Here are a couple of examples that look at playing with more than just simple values.

Create a Google Site Map with ASP.NET

calendar_today 31 December 2008 09:32

ASP.NET 3.5 ASP.NET Web Forms

Over Christmas, I had a bit of spare time, so I decided to add some functionality to this site. One of the things that I added was the ability for people to post comments about specific articles, and you will see that a form has been added at the end of this article. The other thing I have been meaning to get round to is to add a Google Site Map. I believe I have created my site to be as friendly to Google's bots as possible, but there is no harm in submitting a site map to guarantee that Google knows about all the pages I want indexed.

Import Data From Excel to Access with ASP.NET

calendar_today 09 July 2008 09:19

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

Building on my previous article on importing text files of various formats to an Access database, here's how to do the same thing simply and efficiently with Excel files.

AccessDataSource, SqlDataSource and connecting to Access databases in ASP.NET

calendar_today 17 May 2008 09:48

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

There are a variety of options for connecting to Access databases within ASP.NET pages. This article attempts to cover the choices and offer recommendations for getting the best out of Access.

80040E14 - MS Access Syntax Error messages

calendar_today 01 May 2008 11:06

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

This short article deals with the following common MS Access-related error messages:

Simple Login and Redirect for ASP.NET and Access

calendar_today 01 May 2008 10:02

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

Quite often, I see questions asked about creating a simple login page for use with Access from people who don't want to take advantage of the built-in Forms Authentication framework within ASP.NET. The following samples show how relatively easy this is to accomplish.

Search Engine-Friendly Custom Paging with the GridView and LINQ to SQL

calendar_today 20 November 2007 22:54


The main problem I find with the built-in paging functionality offered by the GridView control is that the paging links are managed by Javascript. This is a bit awkward for people who disable, or don't have Javascript in their browser, but more importantly, the links can't be triggered by search engines. If you rely on the GridView to paginate links to content, this can prove disastrous, and much of your content will be inaccessible to search engines. Motivated by Scott Guthrie's series of blog entries on LINQ to SQL, available in the .Net 3.5 framework, I set about getting some custom paging working with html paging links.

An ASP.NET Search Engine with MS Access for optional search criteria

calendar_today 12 November 2007 15:15

ASP.NET 2.0 MS Access ADO.NET ASP.NET Web Forms

Creating a search interface for one user-supplied value is pretty straightforward: a TextBox for input, a Button and some SQL that searches one or more fields where the values are LIKE '%' + @searchterm + '%' is all that is needed. While it works, this approach is not very flexible. For example, what if you wanted to search for an Employee whose last name contains "a", and don't want those where the first name or city contains "a"? The traditional solution to this is to dynamically construct the SQL statement based on what values were passed by the user. However, building the SQL string can get repetitive, boring and messy. Here is a cleaner way to allow the user to narrow down searches across multiple criteria with the use of optional parameters, and just 3 lines of programming code.

Referencing CheckBoxes in GridView, Repeater and DataList controls

calendar_today 30 August 2007 10:29

ASP.NET 2.0 ASP.NET Web Forms

If you want to find which CheckBoxes were selected in a multiple record DataBound control, the way that you you do it depends on the type of control you use. These examples demonstrate a CheckBox control being added to a GridView, Repeater and a DataList. For simplicity, I have placed all three controls on the same page, and used the Access version of theNorthwind database. One AccessDataSource control is used to bind the results of "SELECT [CategoryID], [Description], [CategoryName] FROM [Categories]" to all three controls.

ViewState, form fields, labels and Javascript

calendar_today 25 August 2007 12:34

ASP.NET 2.0 Javascript ASP.NET Web Forms

An interesting question came up on the ASP.NET forums asking why a TextBox which has its value changed by client-side Javascript persists those changes across postbacks, while a Label does not. And in a nut shell, this question covered two of the biggest causes of confusion among newcomers to ASP.NET: the difference between ViewState and IPostBackDataHandler; and the difference between client-side operations and server-side operations.

Bind Data From a SqlDataSource to a Label

calendar_today 25 August 2007 10:32


Label controls in ASP.NET don't have a smart tag that allows you to select a data source, so at first glance, it is not easy to see how to bind a value returned from a SqlDataSource or AccessDataSource control to the label. Here's how to programmatically access the data returned by such a DataSource and apply it to a non-databound control.

Object reference not set to an instance of an object and INamingContainer

calendar_today 21 August 2007 11:36

ASP.NET 2.0 ASP.NET Web Forms

A list of standard ASP.NET web controls that implement INamingContainer

Consuming RSS feeds in an ASP.NET page

calendar_today 18 August 2007 23:12

ASP.NET 2.0 ASP.NET Web Forms

I like reading Scott Guthrie's blog. Trouble is, I get so busy, I forget to go over there and have a look to see what's new. I was searching for something the other day, and stumbled across someone else's blog (I forget whose), but I noticed that they had the 5 most recent items in Scott's blog embedded in their home page. It was only then that I discovered that Scott Mitchell has written a whole load more tutorials on Data Access, and that these have been available for a while. So I got to thinking that I should add a feed from Scott G's site onto the home page here, so I can be updated more quickly. Here's the bare bones of how I did it.

Displaying One-To-Many Relationships with Nested Repeaters

calendar_today 27 July 2007 14:24


This item could also have been entitled "Displaying Master-Detail Data" or "Displaying Categorised Data", but the principal is the same: you have what are essentially headings or categories, and a group of entries that belong to each heading that you want to display. Typical examples would include the Models of cars by Manufacturer, or Employees by Department. Here's how to do it quite simply using nested Repeaters.

Customising a ListControl's DataTextField value

calendar_today 06 July 2007 12:19

ASP.NET 2.0 ASP.NET Web Forms

The DataTextField property is used with ListControls - RadioButtonList, CheckBoxList etc to specify a field in the DataSource property to display as the items of the list in the list control. Sometimes, however, you don't want just the value from one database field to appear in the list, and there are a couple of ways to achieve this, depending on what you want to do.