Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Role to User Created in Web.config

Tags:

asp.net

roles

I have a few users setup in the web.config of an asp.net site to handle authentication. Without getting into details I'm not using the full membership/role provider and would rather not have to implement it at the moment do to time constraints. However I do need the ability to assign a role to a user so that securityTrimming works on the sitemaps associated menus.

For now I just have a few users setup in the web.config (i use SHA1 in real config)

<authentication mode="Forms">
    <forms name="Auth" loginUrl="~/login.aspx" defaultUrl="~/admin/default.aspx" requireSSL="true">
        <credentials passwordFormat="Clear">
            <user name="admin" password="test"/>                
        </credentials>
    </forms>
</authentication>

Is it possible to also assign a Role to one of the users in the credentials section or elsewhere without setting up an actual role provider? Something similar to how I have the users setup above.

like image 386
Brian Boatright Avatar asked Dec 02 '08 17:12

Brian Boatright


2 Answers

This is not possible to do via the web.config, you will need to setup the membership provider, but using the .exe to create the database tables, the whole process literally takes under 5 minutes to complete!

like image 106
Mitchel Sellers Avatar answered Oct 07 '22 01:10

Mitchel Sellers


I've had the same "issue" a couple of times now, so I finally implemented a simple iRoleProvider implementation that uses web.config. Check it out on Codeplex, Web.Config Role Provider .

like image 27
Jakob Gade Avatar answered Oct 07 '22 01:10

Jakob Gade