0

I have a Web Forms site in ASP.NET using C#. I have a folder that I like to modify so only certain users can access it. I've already done this through the web.config file of the folder with:

<authorization>
 <allow users="User1, User2, User3" />
 <deny users="*" />
</authorization>

But I have a string list with all the users that need to be put in the 'allow users' attribute. The string list gets populated by a Table in the database. So I want to use the string list or the database instead of manually writing all the users in 'allow users' attribute. How do I do this? Even if using AppSettings, still don't know how to actually do that.

2 Answers 2

1

I would suggest that instead of using the user you instead use Roles. You can add the role to the allow list and give all the users that match the database the required role when logging in using a RoleProvider.

Here is a link to a pretty thorough article on how to achieve this http://www.codeproject.com/Articles/607392/Custom-Role-Providers. It is an MVC example but can also be adapted for web forms, if you are using that. It also shows turning off and on elements based on the roles.

Sign up to request clarification or add additional context in comments.

3 Comments

Tried doing it with Roles, but I can't get it to work. I failed to mention that I'm a beginner, if it isn't obvious. And there is not Web Configuration Tool in VS 2013, so managing Roles and Membership isn't that easy. My way is a good alternative since I can make certain elements (buttons, boxes, menus or whatever) visible for the list string of users
Your way may be good way to solve problem but instead of saying "My way is good alternative" you should at least listen other's opinions especially when you are beginner and want to learn from other's experience. Be open minded my friend.
I'm not saying my way is better, actually it's way worse. But I already tried with Roles and Memberships as I said, and I can't do it. So that's why I'm asking this question
1

So I found this question:

Is it possible to reference a value from an SQL database in a web.config file?

And I found that you actually can't. Which is weird because I have come across some info that you can with AppSettings, but ok. I managed this without the web.config file, I just redirected the users to the homepage if they weren't in the string list.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.