Adding Role to User Created in Web.config

2019-06-16 07:32发布

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.

标签: asp.net roles
2条回答
放荡不羁爱自由
2楼-- · 2019-06-16 07:59

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 .

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-06-16 08:01

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!

查看更多
登录 后发表回答