Use WCF Service with basic authentication user

家住魔仙堡 提交于 2019-12-13 21:16:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!