ASP.NET Web Forms
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.
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.
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.
calendar_today 26 January 2016 07:39
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.
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.
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.
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.
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.
calendar_today 17 July 2015 13:43
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.
calendar_today 07 July 2015 13:49
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.
calendar_today 30 June 2015 14:47
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.
calendar_today 07 August 2014 08:34
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.
calendar_today 23 June 2010 07:43
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.
calendar_today 22 May 2010 19:41
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.
calendar_today 06 December 2009 19:46
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.
calendar_today 25 November 2009 09:09
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?
calendar_today 10 January 2009 09:09
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.
calendar_today 31 December 2008 09:32
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.
calendar_today 09 July 2008 09:19
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.
calendar_today 17 May 2008 09:48
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.
calendar_today 01 May 2008 11:06
This short article deals with the following common MS Access-related error messages:
calendar_today 01 May 2008 10:02
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.
calendar_today 20 November 2007 22:54
calendar_today 12 November 2007 15:15
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.
calendar_today 30 August 2007 10:29
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.
calendar_today 25 August 2007 12:34
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.
calendar_today 21 August 2007 11:36
A list of standard ASP.NET web controls that implement INamingContainer
calendar_today 18 August 2007 23:12
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.
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.
calendar_today 06 July 2007 12:19
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.