Hidden Features of ASP.NET

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here.

More info: https://stackoverflow.com/faq


There are always features that would be useful in fringe scenarios, but for that very reason most people don't know them. I am asking for features that are not typically taught by the text books.

What are the ones that you know?


While testing, you can have emails sent to a folder on your computer instead of an SMTP server. Put this in your web.config:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="c:Temp" />
        </smtp>
    </mailSettings>
</system.net>

If you place a file named app_offline.htm in the root of a web application directory, ASP.NET 2.0+ will shut-down the application and stop normal processing any new incoming requests for that application, showing only the contents of the app_offline.htm file for all new requests.

This is the quickest and easiest way to display your "Site Temporarily Unavailable" notice while re-deploying (or rolling back) changes to a Production server.

Also, as pointed out by marxidad, make sure you have at least 512 bytes of content within the file so IE6 will render it correctly.


throw new HttpException(404, "Article not found");

This will be caught by ASP.NET which will return the customErrors page. Learned about this one in a recent .NET Tip of the Day Post

链接地址: http://www.djcxy.com/p/46818.html

上一篇: Cache之间有什么区别

下一篇: ASP.NET的隐藏功能