简体   繁体   English

使用SQL登录名和ASP.NET MVC登录到SQL Server

[英]Logging in to SQL Server using SQL logins with ASP.NET MVC

I am writing a small addon mobile app to an existing applications database, the application stores login details through SQL Server logins: 我正在向现有的应用程序数据库中编写一个小型插件移动应用程序,该应用程序通过SQL Server登录名存储登录详细信息:

登录

I want to be able to use these existing logins (and permissions if possible) in my mobile web app but I can't find if there is an easy way to do this. 我希望能够在我的移动Web应用程序中使用这些现有的登录名(如果可能的话,还有权限),但是我找不到是否有简便的方法来执行此操作。 I was hoping there would be an existing provider that would allow me to do this via the web.config. 我希望有一个现有的提供程序,允许我通过web.config进行此操作。

Is there any way to do this without having to code all the login/authentication manually? 有什么方法可以不必手动编码所有登录/身份验证的方法吗?

eg: 例如:

<providers>
    <add name="SQLProfileProvider" type="System.Web... />
</providers>

Alternatively does anyone know of any resources that could help me do it manually? 另外,有人知道有什么资源可以帮助我手动完成吗?

Please don't judge to harshly if I'm being an idiot, this is my first foray into asp.net! 如果我是个白痴,请不要苛刻,这是我第一次进入asp.net!

Update: 更新:

Maybe it wasn't clear what I am trying to do so I will try and expand. 也许不清楚我要做什么,所以我会尝试扩展。

I have an existing desktop application (not under my control). 我有一个现有的桌面应用程序(不受我的控制)。 It uses SQL Server 2008 to store it's data and it authenticates users using SQL Server Logins. 它使用SQL Server 2008来存储其数据,并使用SQL Server登录名对用户进行身份验证。

I am writing a web app to connect to this database. 我正在编写一个Web应用程序以连接到该数据库。 I want to allow users to log in to the web app with their existing login details from the desktop application. 我想允许用户使用桌面应用程序中的现有登录详细信息登录Web应用程序。

eg. 例如。 I have a database with the user 'abc123': 我有一个数据库,用户为“ abc123”:

在此处输入图片说明

I want to be able to use this login within asp: 我希望能够在ASP中使用此登录名:

登录画面

I know this is possible using my own membership provider within MVC but if this has already been written I would love to be able to use an existing membership provider . 我知道可以在MVC中使用我自己的成员资格提供程序,但是如果已经编写了此文件, 我希望能够使用现有的成员资格提供程序

Does anyone know if this membership provider exists? 有人知道这个会员资格提供者吗?

The question is interesting in fact. 这个问题实际上很有趣。 I've never heard of an out-of-the-box membership provider that directly uses sql logins. 我从未听说过直接使用sql登录名的现成的成员资格提供程序。 So, my answer is 'no that doesn't exist'. 所以,我的回答是“不,不存在”。

I can't imagine it would be terribly difficult to write however. 我无法想象这将很难编写。 Just implement the MembershipProvider ( http://msdn.microsoft.com/en-us/library/System.Web.Security.MembershipProvider(v=vs.110).aspx ) and run sql scripts for all of the 'CreateUser' stuff. 只需实施MembershipProvider( http://msdn.microsoft.com/zh-cn/library/System.Web.Security.MembershipProvider ( v=vs.110 ) .aspx )并为所有“ CreateUser”内容运行sql脚本。 It should work in a very straight forward manner. 它应该以非常直接的方式工作。

I would just note that this is a very non-traditional use of the db logins. 我只需要注意,这是数据库登录名的非常传统的用法。 But I see how you would instantly get the benefits of any permissions applied to the users/roles setup in the database. 但是我看到您将如何立即获得应用到数据库中用户/角色设置的任何权限的好处。 This is not very scalable, but you would have very granular permissions in place. 这不是很可扩展,但是您将拥有非常精细的权限。

Maybe a more scalable solution would be to have a users table mapped to generic logins that represent certain types (eg ReadOnlyLogin, WriteableLogin, etc.) That way you may have 100 users, with usernames and passwords in a table, and then have them assigned to a particular dblogin (mentioned above). 也许更具可扩展性的解决方案是将一个用户表映射到表示某些类型(例如ReadOnlyLogin,WriteableLogin等)的通用登录名。这样,您可能有100个用户,并在一个表中包含了用户名和密码,然后分配了它们到特定的dblogin(如上所述)。 When a user logs in, you would then use the given login whenever they accessed the db, enforcing any permissions set on the login. 用户登录后,只要他们访问数据库,便会使用给定的登录名,从而强制对登录名设置任何权限。 So, Bob, Frank, and Harry would use ReadOnlyLogin, and Sally, Jane and Samantha would use WriteableLogin. 因此,Bob,Frank和Harry将使用ReadOnlyLogin,而Sally,Jane和Samantha将使用WriteableLogin。 Just a thought. 只是一个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM