Alternate (user-scoped) settings in a C# desktop application

£可爱£侵袭症+ 提交于 2019-12-11 13:40:47

问题


1) I use Visual Studio 2008 (C#)

2) I want my desktop application to "remember" certain settings (preferences) for every user individually.

3) The application would use its own database of users (logins + passwords), so they have nothing to do with Windows accounts.

How can I accomplish that? Trying to find an answer

4) I've found the "Using Alternate Sets of Settings" subject on MSDN => http://msdn.microsoft.com/en-us/library/aa730869%28VS.80%29.aspx - but

5) it suggests that even these alternative settings need to be added in design time. That's a bit of a problem, because:

6) I don't know in advance, how many users would be in the database - and I want the "main user" (admin) to have an option of adding more accounts any time he wants.

So 7) how do I accomplish that?

So far I thought about: 8) using isolated storage files? (but they, too, are user-scoped in the sense of referring to Windows accounts)

9) deriving my own class from ApplicationSettingsBase class and supplying it with a SaveAs() method (which it lacks by default)?

Thanks for any answers / suggestions. If my problem is not quite clear, I'm happy to clarify


回答1:


If you have a database that stores users and passwords, why not store the application settings there as well? I'm assuming you're using SQL Server (Express or commercial)

All "Settings" are in .NET are key, value pairs, and I don't see why you couldn't accomplish this exact same functionality with a name value pair in the database.

I've found that the "Settings" and Configuration management tools are confusing and tricky to use, so if you have a database with users in it already, you might as well leverage your existing infrastructure.




回答2:


You could use a SQLite database to hold all the data. (See System.Data.SQLite)




回答3:


You should think about using the ASP.NET Membership provider. It allows for per-user personalization settings as well as 'all user' settings.

It was built for web sites, but you can configure it for use in a desktop application pretty easily. Also, there is a whole API that is already written for it.



来源:https://stackoverflow.com/questions/1381115/alternate-user-scoped-settings-in-a-c-sharp-desktop-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!