开发者

Add a web User to SQL without using ASP.NET Configuration button in Visual Studio

Hello how can I add users and give them roles without using the ASP.NET Configuration button in Visual Studio

I wrote a web site that requires a login.

I am not using SQL express to 开发者_JS百科hold user information I ran aspnet_regsql and configured some users using the ASP.NET Configuration button. I uploaded the database to the server and no I need to add a user.

By boss is in a meeting with the client at this very moment so this is failry urgent.

I hope an pray that I have explained what I want well enough to get some help.

There must be a way of going to the server database and adding a user. Many thanks


This is all in the Membership Provider and can be controlled programatically. The best place to start is look at a complete overview, as it will help you better understand how to do this. As an example: https://web.archive.org/web/20211020202857/http://www.4guysfromrolla.com/articles/120705-1.aspx

Do not try to do this using SQL Queries alone, unless you have configured the membership provider to use no encryption. If you try to circumvent, which is possible in some instances, you will mess things up. In the standard Membership Provider, you have methods to create users and put them in roles. It is a bit kludgy and I have personally customized a bit to make things easier, but the standard classes are not that unwieldy with creation of users and putting them in roles (big issue was changing without a customized membership provider).


First in master database:

use master
go
create login [loginname] from windows

--- OR --- create login [loginname] with password='passw0rrrd' go

Then in your database

use your_database
go
create user [username] from login [loginname]
go
exec sp_addrolemember 'db_datareader', 'username'
exec sp_addrolemember 'db_datawriter', 'username'
grant execute to [username]
go

This should sort you out. In long term it is better to create a database role with required permissions. The only thing you have to do then is to add user to this role.

Regards

Piotr

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜