English 中文(简体)
C# 公共静态方法 - 用户共享信息
原标题:C# public static method - shares info between users
  • 时间:2012-05-24 19:43:12
  •  标签:
  • c#
  • static

我有一个 asp.net 网站和一个班级图书馆作为项目参考。 在班级图书馆里, 我有一个公共类的静态方法。 当用户登录到他们的账户时, 我给一个静态方法打电话, 以装入与用户有关的信息。 我有一些例子, 我登录到用户 A 时, 我能看到与用户 B 有关的信息。 这是因为静态方法吗?

最佳回答

否, 是因为静态 变量 。 这些由整个 AppDomain 共享 - 这几乎意味着“ 机器上的整个网站 ” 。

很难确切地知道在没有任何更多信息的情况下你应该做什么,但我强烈怀疑你只是将用户信息储存在静态变量中,这就是`它们'永远不会是正确的方式。

您如何管理用户会话由您决定, 并且毫无疑问, 已经为此撰写了文字的重写- 但使用静态变量将引发您所看到的问题 。

问题回答

这可能是,我不得不看你的代码是肯定的,信息是否也作为静态存储起来?那么,它是正确的,因为静态在两种情况之间是共享的。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签