开发者

Removing / Ignoring Session items that will cause .NET deserialization errors

开发者 https://www.devze.com 2023-01-19 00:52 出处:网络
I\'m trying to be clever by allowing a small validation method to be defined \"inline\" in ASCX templates as an Action<,>, like so:

I'm trying to be clever by allowing a small validation method to be defined "inline" in ASCX templates as an Action<,>, like so:

<%= OnValidation(delegate(FormSubmission form, FormResult errors) {
    // form checks in here, append errors to errors variable if required
}) %>

It actually works a treat, but in order to ensure it can be called during postbacks I need to store the method in the session against that form ID. This also works, up until the point where the app needs to rebuild or references chan开发者_运维知识库ge, then the whole thing crashes out because it can't find "App_Webxxxx" in order to deserialize the methods that are left in the user's session (I guess this wouldn't happen if I was using InProc sessions as clearing my cookies gets rid of the error, but it has to work in SQLServer mode too).

To this end, is there a way to remove those types of items before they cause problems or simply ignore them (the lazy option, I know)? I can't just remove them after they've been run as the user may not submit the form. The best I can think is to do some checking on Application_Start, but I'm not sure if that will even execute, and what to check for.

Any clues very much appreciated!

0

精彩评论

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

关注公众号