我有一个 MVC 4 应用程序,它使用 EntityFramework 4 连接到后端数据库。我正在尝试使用可信连接,以便只要查看网页的用户有权访问数据库,我就希望使用他们的 Windows 帐户进行连接。我搜索了解决方案,并将以下内容放入我的 web.config 中:
<system.web>
<authentication mode="Windows"/>
<identity impersonate="true"/>
...
我的连接设置如下:
<add name="MyDbEntities" connectionString="metadata=res://*/MyDbEntities.csdl|res://*/MyDbEntities.ssdl|res://*/MyDbEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=MyServer;initial catalog=MyDb;integrated security=True;Trusted_Connection=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
我也尝试过模拟和委托(delegate),但到目前为止,我无法克服错误:
Login failed for user ''. The user is not associated with a trusted SQL Server connection.
我见过的所有解决方案都建议修改托管服务器上的 IIS,但我无法在我们的 QA 或生产环境中执行此操作。因此,我试图找到一种仅使用代码的解决方案,无论是我可以在 JavaScript 中执行的操作,还是在 Controller 中执行的操作,或者在底层业务或数据层中执行的操作。
预先感谢您的任何建议!
最佳答案
关于asp.net-mvc - 使用 EntityFramework 将浏览用户的凭据传递到 MVC 4 应用程序中的数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19252689/