What is Toluu?
Toluu is a free service for sharing the feeds you read and discovering new ones.
Get Invite

.NET Tip of The Day.org

Learn one new .NET trick every day


How to respond with code 404 (Not Found) in ASP.NETAugust 26

Suppose you configured custom 404 page in web.config file in the customErrors section. So whenever user requests non-existent aspx page, ASP.NET run-time returns well formatted message to the user.

Also you have a page that shows articles from a database according to article ID passed in the url (for example: article.aspx?id=345). But if user passes article ID that doesn't exists the page must return code 404 (Not Found) and show the custom 404 page like in the previous situation.

Fortunately you don't need to parse the customErrors section to get name of the custom 404 page. Just throw HttpException:

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

ASP.NET run-time will catch the exception and will redirect to the custom 404.


img.phdo?x=52ddf431a6834c29b72e7f6214a23d5a&u=how-to-respond-with-code-404-not-found-in-aspnet

Code snippets for some common operations with exceptionsMay 19

Download and install these additional code snippets for common operations with exceptions. To use them type shortcut for the code snippet that you want to add to your code and then type Tab, Tab to invoke it.

  • thr - throw new
  • thrni - throw new NotImplementedException("");

img.phdo?x=52ddf431a6834c29b72e7f6214a23d5a&u=code-snippets-for-some-common-operations-with-exceptions
dotNetTipOfTheDay?i=fkSCDh dotNetTipOfTheDay?i=3KjNvH dotNetTipOfTheDay?i=P0v8Yh

News: .NET Tips & Tricks Community RSSMay 10

Those who prefer reading this site through RSS now can also subscribe for updates to .NET Tips & Tricks Community.

dotNetTipOfTheDay?i=POesdh dotNetTipOfTheDay?i=Ot8BcH dotNetTipOfTheDay?i=yGnfBh dotNetTipOfTheDay?i=mxk8Gh dotNetTipOfTheDay?i=qXjfcH
287471825
Send an e-mail any time an unhandled exception occursMay 10

Consider using built-in ASP.NET health monitoring to monitor your website. Especially if you are not monitoring it at all yet. ASP.NET health monitoring contains ready-to-use Web health-monitoring events classes (Web events) and health-monitoring providers (listeners). For example, you can easily configure it to send an email any time an error is detected.


img.phdo?x=52ddf431a6834c29b72e7f6214a23d5a&u=send-an-e-mail-any-time-an-unhandled-exception-occurs
dotNetTipOfTheDay?i=otusMh dotNetTipOfTheDay?i=T5LXJH

News: Why does new tips appear on this site so infrequently?May 7

Hi guys. I know some of you are not satisfied with the frequency new tips appear on this site. The last comment I received was a proposal to rename the site to .NET Tip of The Month :) But I don't want to do this because I'm going to fix this problem. I'm working on the .NET Tips & Tricks Community section now. My tips that are too small to hit the front page were added to this section. It's the place where all of you can share your .NET tips and tricks.

It's clear that this section lacks for some features. And if anyone out of 2510 subscribers has a proposal, just drop me a line. My email is kostya.ly@gmail.com.

Thanks for you patience.
Kostya Ly

dotNetTipOfTheDay?i=7ilPPh dotNetTipOfTheDay?i=oT1Y3H dotNetTipOfTheDay?i=XZA1Rh