简体   繁体   中英

membership provider with hardcoded users and roles

I have fully working custom membership provider with implemented many features. Now this is ok for serious applications, but I'm wonder how can I implement membership provider, with hardcoded usernames and corresponding roles, for example

  • userOne = Admin access
  • userTwo = Limited access
  • userThree = read only

I do not need any crud operations, maybe edit password later, but now it's not important, cause I want to find a way around fully membership provider, in this situation it's overengineered solution.

Any links, ideas, code examples are welcomed.

Thanks

Why would you want to do that?

Anyway, you Dictionary to do so.

Here's an example.

Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("userOne", "Admin access");

string access = string.Empty;
dic.TryGetValue("userOne", out access);

You can call dic.Add() as many times as you want. You can even pull data from text file using FileSystem or from Database. You can also pass a variable with TryGetValue .

string username = txtUserName.Text;
dic.TryGetValue(username, out access);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM