While it is certainly possible to log details such as the client computer's IP address and the paths that a user visits to a database, you'll find that your database will get quite large very quickly. Unless you have a very good reason to implement this level of detail in your logging, it's almost always overkill.
The fact that ASP.NET maintains a user's session state for us is a great thing. That being said, session state does come at a cost and disabling it when you're not using it is a standard tip for improving application performance. But what should you do if you are using it?
Trying to quickly make sense of unfamiliar code can be quite frustrating. This tip will show you how to instantly jump from the usage of a subroutine directly to its definition using any flavor of Visual Studio. This huge time saver lets you easily locate code that you might otherwise have spent hours trying to find.
I recently spoke with a developer who was upset that the redundancy he built into his
Web application had failed him. As a safeguard against database failure, he had written
a script which wrote new entries to a log file on the local file system as well as
adding them to the database. It was a good idea... unfortunately the implementation
wasn't so good.
Everyone who's used ASP.NET master pages knows that you can specify which master page a content page should use via the content page's Page directive. Most people also know that you can also set it either programatically via code or via the Web.config file. But did you know you can also set it by folder?
I recently received an email in reference to my old ASP.NET RSS feed reader which asked how to display multiple RSS feeds on the same page. The updated code does just that while also illustrating how to write more modular code.
This sample walks you through how to load an image from the file system, perform some simple image manipulation on it using ASP.NET's graphics capabilities, and return the resulting image to the browser. For illustration, three different transformations are applied to the image.
As always seems to happen this time of year, I find myself wondering where the year went. Our faithful readers will probably recall that my usual reaction to this feeling is to take a few minutes out of the hectic holday season to look back and highlight some of the best content we published this year. So without any further ado... here's ASP 101's year in review for 2008.
Did you know that you can register a custom server or user control in your web.config file and use it throughout your application without the need for the <%@ Register %> directive at the top of each page?
When you add a new page to your Web site, do you often find yourself cutting and pasting from another page to get started? If you're spending more time importing controls and setting up content regions for your master page than actually working on the new page, you might want to look into creating an "Item template" in Visual Studio.
It appears that ASP.NET actually includes a Response.RedirectLocation property which you can set instead of using the AppendHeader method we originally used in our tip about permanent redirects. The end result is the same, but based on the feedback we've received it seems that many of our readers prefer the RedirectLocation method.
As often happens, a visitor has taken one of our scripts and improved upon it.
Our original was designed to mimic VB's vbProperCase format. The problem is that they both fail
miserably on things like "Peter O'Tool" or "Camilla Parker-Bowles".
This new version handles both of those correctly.
We've all used Response.Redirect at one time or another. It's the quick and easy way to get
visitors pointed in the right direction if they somehow end up in the wrong place.
But did you know that Response.Redirect sends an HTTP response status code of "302 Found"
when you might really want to send "301 Moved Permanently"?
I've gotten a number of email from users anxious to use HttpOnly cookies in their legacy Web projects. Rest assured, you can get the same HttpOnly functionality regardless of your server side tool of choice... it's just takes a little more work.
Did you know that there's a simple little change you can make in the way you handle cookies that can help prevent your users from falling victim to a cross-site scripting attack? Implementing HttpOnly cookies is quick, easy, and goes a long way towards making your application safer for everyone.
This sample illustrates the basics of how to use the Ad Rotator control. The control is easy to use, and just like its .NET counterpart, it can be useful even if you're not actually serving advertisements.
This sample illustrates the basics of how to use the ASP.NET Ad Rotator control. The control is quite simple and even if you're not actually serving advertisements it's a great way to rotate the display of other images as well.
We must've done something right when we wrote this sample, because it's ten years later and users are still using it and even sending us their own customized versions. Quite a few changes in this version. If any of these features are something you think might be useful, download it and give it a whirl!
Our login and password sample code has always been case-sensitive. While we don't really recommend it, if you must make your usernames and/or passwords case-insensitive, it's actually quite easy to do.
While developers are usually interested in accessing the data contained within a database's tables, occasionally you need to know something about the tables themselves. It's at these times when this quick ASP.NET tip might come in handy.
This sample illustrates how ASP.NET handles the problem of maintaining a Web form's ViewState for you automatically. As such, the actual code involved is not that exciting, but the fact that it does all the work for you should excite you some.
Did you know that you can move sections of your Web.config file into other files? Whether it's to keep things tidy or simply to make it easier to find the settings you change often, it's easy to do and yet few people even realize you can.
As a developer, repetitive code is your enemy. It takes longer to write, leads to larger files, and is harder to maintain. Which brings me to the point of this tip. Did you know that you can tie the same event handler to multiple objects? It's easy to do, but most people never think to try it.
Microsoft just published a series of 46 -- that's right 46! -- tutorials that provide step-by-step
instructions for implementing the different controls in the ASP.NET AJAX
Control Toolkit. If you've been putting off messing with AJAX, what can
I say... sometimes procrastination does pay off!
Why do people insist on using mm-dd-year or dd-mm-year when creating
log files? Are you really trying to see what happened on the same
month of every year or the same day of every month? You might want
to try this alternative, which when sorted numerically actually puts
the files into chronological order.