FAtBalloon
FAtBalloon

Reputation: 4500

C# .NET - Membership.ValidateUser returns false in web; true in visual studio

When running a web in visual studio, the following line returns true.

if (Membership.ValidateUser(Login1.UserName, Login1.Password))

However, the moment I access the same code through a web, it returns false.

Same database, same computer, same web folder, the only difference is that when I'm running through debug in visual studio, it works and when I'm trying to access it through a web, it fails.

Thanks

Upvotes: 2

Views: 1808

Answers (3)

palehorse
palehorse

Reputation: 27476

If you are using SQL Express, make sure that the folder the database resides in has permissions for the IIS worker process user to modify. On Windows XP it is typically the IIS_ or ASPNET user. On Windows 2003+ this should normally be the NETWORK SERVICE group.

Upvotes: 1

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65391

When you are in debug mode you are in the security context of the user you are logged in as.

When you access over the web you may be in the context of the same user or the IIS anonymous user or the identity of the application pool depending on your configuration.

If you configure IIS and web.config to use windows authentication and impersonate = true, you should get the same result.

Upvotes: 3

tvanfosson
tvanfosson

Reputation: 532455

Does your web site worker process have access to connect to the database (or AD)? Perhaps, the credentials used for the worker process are not able to connect and thus the lookup fails. This is often the case when you have the connection string set up to use integrated authentication. When you run in Cassini or in unit tests, it will use the credentials of the logged in user who often has more rights than the worker process.

Upvotes: 1

Related Questions