序列HttpContext对象存储在数据库中 [英] Serializing HttpContext object to store in a database

查看:103
本文介绍了序列HttpContext对象存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个C#ASP.Net MVC的网站。我想存储在SQL Server中供以后分析包含在 HttpContext.Current.Request 对象在一个表中的一切。

We have a C# ASP.Net MVC website. I would like to store everything contained in the HttpContext.Current.Request object in a table in SQL Server for later analysis.

我试图序列化对象转换成字节数组,然后将其存储在SQL Server中的二进制字段,但是串行不会序列化的HttpContext 对象,因为它是没有标记序列化

I attempted serializing the object into a Byte Array, then storing it in a binary field in SQL Server, however the serializer won't serialize the HttpContext object since it is not marked Serializable.

有没有什么办法来标记的System.Web类为可序列化?还是有另一种方式来做到这一点?

Is there any way to mark a System.Web class as serializable? Or is there another way to accomplish this?

推荐答案

有关生产code,我不相信你可以改变的HttpContext的序列化的方面。如果这是非生产性你可以尝试修改大会插入Serializable属性(但可能需要在子类做得太)使用如反射和一些插件的工具。

For production code, I don't believe you can change the serialization aspect of the HttpContext. If this is non-production you might try modifying the Assembly to insert the Serializable attribute (but that may need to be done on sub-classes too) using a tool like Reflector and some plug-ins.

什么可能是更容易的选择是使用反射来枚举所有公共和私人领域。你可以简单类型转换为它们的字符串重新presentation和递归上是稍微复杂的类。你甚至可以找到一个工具来做到这一点,这个想法可能会被称为询问的对象图浏览器。

What might be an easier option would be to use Reflection to enumerate all the public and private fields. You could convert simple types to their string representation and recurse on classes that are slightly more complicated. You might even be able to find a tool to do this, the idea would probably be referred to ask an Object Graph viewer.

这篇关于序列HttpContext对象存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆