问题
We are working on a pretty standard website that uses a WCF service to retrieve data from a database.
The Website (ASP.Net MVC) has a Service reference to the WCF Service The WCF Service has access to the database
We need to enable basic authentication on the site as part of our requirements.
When we enable it on the site, and leave it disabled on the WCF service, the site asks for the credentials but the SQL Server throws an error saying that the login failed for the user 'NT AUTHORITY\IUSR'.
If we enable it on both the site and the service, when we try to execute a query after creating a "Client" instance of the service, it throws an exception saying "The username is not provided. Specify username in ClientCredentials.".
I know I could just configure the service to run as a particular user that has access to the database or "hard code" the credentials in the creation of the service client, but the logic in some of the stored procedures (that we don't control) rely on knowing who is executing the query.
What is the best approach in this case? Is there a way to automatically pass the credentials used to log into the site to the WCF service?
Thanks a lot!
回答1:
I think it again basically depends on hosting type you are using.
来源:https://stackoverflow.com/questions/19456259/use-wcf-service-with-basic-authentication-user