开发者

.Net Application_Error

In Global.asax i have code in Application_Error handler which stores the error message in HttpRuntime.Cache, logs the error to the application log file and then Transfers the user over to the Error.aspx page to display the message within the website template/theme (by retrieving it from HttpRuntime.Cache).

What i want to know is if there is a good way to manage the HttpRuntime.Cache content.

Currently, i am setting the HttpRuntime.Cache value with a key that is defined in globally available Constants file, and then e开发者_如何学Goxplicitly removing it in the Error.aspx code behind.

Is there a smarter way to ensure that the HttpRuntime.Cache is cleaned up properly once the error handling is complete?

To abstract from the context:

MethodA sets some values in a central storage location Control is transferred to MethodB which uses the values from central storage Only upon successfully reading the values, should MethodB clear the values from storage

Restriction: Control cannot be given back to MethodA. Once MethodB is complete, the program ends.


IMHO you are on the right track.

What I have done in the past is to have a DTO (Data Transfer Object, a lightweight data object) that is used to hold the exception information and is stored in Session. The code which catches the error and forces the redirect to the error page also sets a flag in the DTO to say whether the error is recoverable, and if so it also stores a URL in the DTO - this means the error page can render out a link for the user to click on to go back to where they were interrupted (you are in control of the link, and whatever is on the end of it, so you can send them back to whereever you like within your application, or recreate a page as much as you like for them to continue).

Remember that the Cache is global, so it is possible that you can overwrite one user's exception info with another user's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜