My web application (a WCF service) uses SqlRoleProvider
, which works fine on Visual Studio Development Server. Switching it to IIS8 Express causes it to throw a NullReferenceException
though:
Roles.IsUserInRole(username, role) // neither of them actually null
I could not find a hint for this exception in the IsUserInRole
method documentation. Switching back to Visual Studio Development server makes it work. What is the cause of this exception, and how could I fix it properly? The project's target framework is .NET Framework 4.
Here is the configured connection string:
<add name="ConnectionString"
connectionString="Data Source=.\sqlexpress;Initial Catalog=DevWeb;Integrated Security=True"
providerName="System.Data.SqlClient" />
And this is the roleManager/providers
node:
<clear />
<add connectionStringName="ConnectionString" applicationName="MyApp" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
Fairly sure your issue is going to be with the database and the permission of the account accessing it. Try adding your IIS account to the sa priv and see if the matter resolves. If it does then you have a missing permission.