使用ASP.NET 4.0和SQL Server 2008进行数据库使用的用户/登录系统(User/login system using ASP.NET 4.0 and SQL server 2008

编程入门 行业动态 更新时间:2024-10-10 15:18:33
使用ASP.NET 4.0和SQL Server 2008进行数据库使用的用户/登录系统(User/login system using ASP.NET 4.0 and SQL server 2008 for database use)

我希望根据登录的用户以及各种下拉框和/或文本框输入使数据表动态显示在网页上。

在开始编写动态函数脚本之前,我想确保首先让用户系统工作。 我已经处理了许多具有权限的错误,甚至可以获得可在页面上显示的可编辑数据库以及登录系统。

在使会员系统最终工作之后,我意识到将会有这么少的用户,我可以在SQL Server Management Studio中手动创建它们,而不是使用ASP.net会员系统。 虽然,我不确定每个的功能/功能,并且在我进一步了解之前需要建议。

允许用户使用ASP.NET 4.0和SQL Server 2008登录和访问不同数据库的最佳方法是什么?

I am wanting to make data tables appear dynamically on a webpage based on the user logged in, and through various dropdown boxes and/or textbox inputs.

Before I start on scripting the dynamic functions, I want to make sure I get the user system working first. I have worked through many bugs with permissions to even get an editable database to show on a page, and for the login system.

After making the membership system finally work, I realized that there will be so little amount of users that I could manually create them in SQL Server Management Studio instead of using an ASP.net membership system. Although, I am not sure on the features/functions of each, and need advice before I get too much further.

What would be the best way to allow users to log in and access different databases using ASP.NET 4.0 and SQL server 2008?

最满意答案

好的,所以我的最终解决方案是在SQL中创建用户,并为他们提供密码,并在那里分配数据库。 然后,当他们登录时,程序使用会话变量来保存他们的登录数据。 此代码还测试登录信息,并将标签更改为SQL错误代码(如果生成了一个)。 如果测试通过,它只是重定向到目标页面。

Imports System.Data.SqlClient Public Class login Inherits System.Web.UI.Page Protected Sub LoginButton_Click(sender As Object, e As EventArgs) Handles LoginButton.Click Session("Username") = textUserName.Text Session("Password") = textPassword.Text Session("Database") = textDatabase.Text Dim queryString As String = "LOGINPROPERTY ( '" + Session("Username") + "' , 'property_name' )" Session("ConnectionString") = "Data Source=MyServerNameHere;User ID=" + textUserName.Text + ";Password=" + textPassword.Text + ";database=" + textDatabase.Text Dim connection As New SqlConnection(Session("ConnectionString")) Dim command As New SqlCommand(queryString, connection) Try connection.Open() Response.Redirect("destination.aspx") Catch ex As Exception LabelError.Text = ex.Message Finally End Try End Sub End Class

然后,使用数据库的每个页面都有此代码

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Session("ConnectionString") IsNot Nothing) Then SqlDataSource1.ConnectionString = Session("ConnectionString") End If End Sub

Ok, so my end solution was to create users in SQL, and give them passwords, and assign databases there. Then when they log in, the program uses session variables to hold their login data. This code also tests the login info, and changes a label into an SQL error code, if one is produced. If the test passes, it simply redirects to the destination page.

Imports System.Data.SqlClient Public Class login Inherits System.Web.UI.Page Protected Sub LoginButton_Click(sender As Object, e As EventArgs) Handles LoginButton.Click Session("Username") = textUserName.Text Session("Password") = textPassword.Text Session("Database") = textDatabase.Text Dim queryString As String = "LOGINPROPERTY ( '" + Session("Username") + "' , 'property_name' )" Session("ConnectionString") = "Data Source=MyServerNameHere;User ID=" + textUserName.Text + ";Password=" + textPassword.Text + ";database=" + textDatabase.Text Dim connection As New SqlConnection(Session("ConnectionString")) Dim command As New SqlCommand(queryString, connection) Try connection.Open() Response.Redirect("destination.aspx") Catch ex As Exception LabelError.Text = ex.Message Finally End Try End Sub End Class

Each page which uses the database then has this code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Session("ConnectionString") IsNot Nothing) Then SqlDataSource1.ConnectionString = Session("ConnectionString") End If End Sub

更多推荐

本文发布于:2023-07-27 07:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287120.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   用户   系统   Server   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!