r/visualbasic • VB.Net Beginner • Jul 16 '20

ASP.NET VB Role Manager (SQL stopped working after enabled)

Hi VB Programmers:

I have a web app on my IIS server which is domain connected. I would like to enable role manager so I can use the command If System.Web.Security.Roles.IsUserInRole("DOMAIN\SecGroup1")= "true" Then

so I attempted to place this into my code, but it errored asking me to enable role manager.

After enabling role manager in my web.config file, my SQL connection stopped working.

My SQL connection is simply under ConnectionStrings in web.config which is a string of data source (server name), ID, Password, and provider name.

(Edit: my SQL database has no roles, tables, or anything related to security. I've had this web app for internal use since ASP 2.0 and this was working at one time. I have since moved to ASP 4.0 and then 4.6.1. I just need the ability to verify if someone is a member of AD. Part of my app already reads/writes to AD fields, if that helps.)

What do I need to do to make SQL work again with role provider?

5 Upvotes

4 comments sorted by

1

u/andrewsmd87 Web Specialist Jul 16 '20

Do you have a version of the config file before hand? What error do you get specifically. What does your connection string look like now?

1

u/data1025 VB.Net Beginner Jul 20 '20

I changed my code to HttpContext.Current.User.IsinRole and now it is functioning as it should without giving me an error.

I don't have a copy of the previous config file and my connection string is:

add name="TracerDB" connectionString="Data Source=server01\Sqlexpress1;Initial Catalog=MLog;User ID=mlog;Password=pw#" providerName="System.Data.SqlClient" />

Because it is working now, is this just a different way to check AD groups? I'd like to understand why.

2

u/andrewsmd87 Web Specialist Jul 20 '20

The reason I was asking is because I didn't think your conn string had changed :)

If you're having to use user.isinrole then I don't think your system is tied into AD, I think it's using the asp.net membership provider. If you look at the database that holds your users, does it have tables like

aspnet_user

aspnet_membership

etc.

1

u/data1025 VB.Net Beginner Jul 20 '20

Correct, my connection string is still the same. I don't have a database of users at all, so I am not using the asp.net membership provider.

I assumed since I was using DirectoryServices.DirectoryEntry for things such as reading/writing to Active Directory, I could also check memberships of users.

Thank you for helping me understand.