Unit Testing Authorization on your Controllers
Published 4 years ago
In many of my ASP.NET web applications (mostly MVC or Web APIs) I have a mix of content with endpoints that either require authentication and authorization or that can be accessed anonymously. For example I have mostly public content (such as my own web site) with a protected management (admin) section. Or I have a Web API project with many endpoints protected by authorization but with a few of them publicly available. To ensure you protect your controllers well, you have many different options. In this article I'll show you a short unit test that you can use to ensure your controllers are properly configured when using a mixed authorization scenario.
Read on ...Dirty Tricks for Dirty Problems
Published 16 years ago
A while ago I needed the ability to display a "no image available" image in a list of products when an image for that product was not available on the server.
Read on ...Fun With Linq!
Published 17 years ago
Quite often I have discussed the impossibility of joining data from a database with that of the file system. I discussed it with my team members, mentioned it in trainings and wrote about it recently in this article.
Being able to join data from a database with other data from a file system could be very useful though.
Read on ...Sending Attachments Directly From a FileUpload Control
Published 17 years ago
With previous versions of ASP.NET you couldn't attach an uploaded file directly to a mail message. Instead, you needed to save the file to disk, attach it to the mail message and then when sending the message succeeded you had to clean up the old file again.
This not only meant a lot of work, it also had some security implications. Because the file needed to be written to disk, the account used by the web server required write permissions to a folder to store the attachments.
Now, with the new constructors for the Attachment class from the System.Net.Mail namespace, these problems are gone....
Read on ...Filling a DataTable or DataSet the Quick Way
Published 18 years ago
In .NET 1.x filling a DataSet or a DataTable meant quite some work. You needed to create a Connection object, a DataAdapter and optionally a Command object. Then you had to call the Fill method on the DataAdapter and pass it a newly created DataSet or DataTable.
In .NET 2.0, this code model has been simplified, thanks to the Load method on the DataTable and DataSet classes that takes an IDataReader as a parameter.
Read on ...Easily Embed a Windows Media Player in a Web Page
Published 18 years ago
I keep forgetting the code that's required to embed a Windows Media Player movie in a web page, so I decided to add it to my Snippets collection for easy reference.
Read on ...Send Out XHTML to Browsers That Support It
Published 18 years ago
A while ago I saw this useful tip to instruct an ASP.NET 2.0 application to send the response as valid XHTML / XML.
Read on ...Binding ObjectDataSource controls to Custom Methods
Published 19 years ago
The new ASP.NET 2 data controls, like the SqlDataSource and the AccessDataSource grealty simplify data access in your Web Applications. However, they have one major drawback: they flood your pages with Sql statements. Not so with the ObjectDataSource, that enables you to bind to the results of a standard method in your Business Logic Layer. The ObjectDataSource can in turn be bound to a data aware control, like the new GridView or DetailsView controls
Read on ...Overriding Individual Application Settings
Published 19 years ago
You may have the situation where you want to be able to override application settings for a .NET application only for your particular instance of the application. This is often the case when you are developing the application, you need to change only the local settings, but you don't want to change the config file that is part of the project and under source control. Here we'll explain the solution that .NET provides but isn't so well known.
Read on ...How Do I Pass Credentials to a Web Service that Uses Basic Authentication?
Published 19 years ago
When you're working with Web Services that require authentication, you'll need a way to pass credentials. This snippet shows you how to pass a user name and password to a Web Service that is configured for Basic Authentication.
Read on ...Mobile: False
Crawler: True
I: False