简体   繁体   中英

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:

登录

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. I was hoping there would be an existing provider that would allow me to do this via the 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!

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.

I am writing a web app to connect to this database. I want to allow users to log in to the web app with their existing login details from the desktop application.

eg. I have a database with the user 'abc123':

在此处输入图片说明

I want to be able to use this login within 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 .

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. 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. 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). 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. Just a thought.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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