简体   繁体   English

在 SQL 中保存注册页面数据并在 Visual Basic (Visual Studio 2019) 中验证并重定向到主页

[英]Save registration page data in SQL and validate and redirect to home page in Visual Basic (Visual Studio 2019)

I have an ASP.Net WebForms website with a login and registration form.我有一个带有登录和注册表单的 ASP.Net WebForms 网站。 I to save data in the local database when the user submits the registration form and validate when the user logs into the website.我在用户提交注册表时将数据保存在本地数据库中,并在用户登录网站时进行验证。

I have created a database but now I am struggling to connect the database and save the data into the database and validate the form I need help to connect the database and save the data from the registration form我已经创建了一个数据库,但现在我正在努力连接数据库并将数据保存到数据库中并验证表单我需要帮助来连接数据库并保存注册表单中的数据

there is my code signup.aspx.vb file name有我的代码signup.aspx.vb文件名

Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows
Imports System.Windows.Forms

Public Class Signup
    Inherits System.Web.UI.Page

    Protected Sub signup_button_Click(sender As Object, e As EventArgs)

        Dim con As SqlConnection = New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\AvivProject\App_Data\Database.mdf;Integrated Security=True")
        Dim cmd As SqlCommand = New SqlCommand("INSERT INTO [dbo].[register] ([username],[email],[password],[repeat-password])
VALUES('" + username.Text + "', '" + email.Text + "', '" + Password.Text + "','" + repeat - password.Text + "')")
        con.Open()
        cmd.ExecuteNonQuery()
        MessageBox.Show("You have seccusessfull registered.", "Information", MessageBoxButtons.OK, MessageBoxButtons.Information)
        con.Close()

    End Sub
End Class

and this my front end signup.aspx file name这是我的前端signup.aspx文件名

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Signup.aspx.vb" Inherits="AvivProject.Signup" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <table style="width: 100%">
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server" Text="Username"></asp:Label>
                 <input type="text" placeholder="Enter Username" name="username" id="username" 
                    required dir="rtl" formmethod="post" />
                <asp:Label ID="Label3" runat="server" Text="איימל"></asp:Label>
                <input type="email" placeholder="Enter Email" name="email" id="email" required dir="rtl" formmethod="post"/>
                <asp:Label ID="Label2" runat="server" Text="סיסמא"></asp:Label>
                <input type="password" placeholder="Enter Password" name="password" id="psw" 
                    required dir="rtl" formmethod="post" />
                <asp:Label ID="Label4" runat="server" Text="חזור על הסיסמא"></asp:Label>
                <input type="password" placeholder="Repeat Password" name="reapeat-password" id="psw-repeat" required dir="rtl" formmethod="post"/>

                <asp:Button ID="signup_button" runat="server" Text="Register" 
                    CssClass="registerbtn" />
            </td>
        </tr>
    </table>

</asp:Content>

Please Let me know what is the mistakes that code did not work请让我知道代码不起作用的错误是什么

The real issue and problem?真正的问题和问题?

think about this:想想这个:

Near EVERY web site needs some kind of logon and security system.几乎每个网站都需要某种登录和安全系统。 As a result, you could spend a month or so building your OWN logon and security system.因此,您可能会花费一个月左右的时间来构建您的 OWN 登录和安全系统。 However, it is VERY doubtful all your own work on this matter will EVER match the resources, time and efforts to use an built in security system.但是,您自己在这件事上所做的所有工作都将与使用内置安全系统的资源、时间和精力相匹配,这是非常值得怀疑的。

And there is huge advantages to use the built in system.使用内置系统有巨大的优势。 For example, you can say that a set of web pages is ONLY allowed to be used by say users that are members of the sales security group.例如,您可以说一组网页只允许作为销售安全组成员的用户使用。 And another set of web pages could be secured for say only site administrators.另一组网页可以只对网站管理员进行保护。 All of this security setup can and does occur WITHOUT YOU having to write any code.所有这些安全设置都可以并且确实发生,而无需您编写任何代码。 (you use the IIS internet security settings and model). (您使用 IIS 互联网安全设置和模型)。

As a result of above, then you can apply security to your web site, and NOT have to write code to check for a valid logon, and even better check if the logged on users in question have rights to use a particular web part or parts of the web site.由于上述原因,您可以对您的网站应用安全性,而不必编写代码来检查有效登录,甚至更好地检查相关登录用户是否有权使用特定的 Web 部件或部件的网站。

Now, we OFTEN will still write some code, and say check if a user has rights to do certain actions - say we might have a page that we let ALL logged on users view some data, but we ONLY allow users who are members of say the "portal master" group to be able to delete records.现在,我们通常仍会编写一些代码,并说检查用户是否有权执行某些操作 - 比如说我们可能有一个页面,我们让所有登录的用户查看一些数据,但我们只允许是成员的用户说“门户主”组能够删除记录。

So in some cases, we can use code to check what a user is allowed to do.所以在某些情况下,我们可以使用代码来检查用户被允许做什么。 (their roles). (他们的角色)。

but, regardless of writing some code, the overall setup of logon system, setup of user "roles" etc. should be left to using the built in system.但是,无论编写一些代码,登录系统的整体设置,用户“角色”的设置等都应该留给使用内置系统。

By using that built in system, then you save BOATLOADS of work and time.通过使用该内置系统,您可以节省大量的工作和时间。 Sure, it might take you better part of the day to setup this logon system on, but that is FAR FAR less work then you attempting to roll your own security system.当然,设置此登录系统可能需要您一天中的大部分时间,但这比您尝试推出自己的安全系统要少得多。 And if you roll your own security system, it not going to be all that secure anyway, and will be FAR MORE work to setup and build your own security system.而且,如果您推出自己的安全系统,无论如何它都不会那么安全,而且设置和构建您自己的安全系统需要做更多的工作。

And it gets even better.它变得更好。 If you use the built in security system, then you can drop in the asp.net logon control - and it will auto matic wire up the logon system for you.如果您使用内置的安全系统,那么您可以放入 asp.net 登录控件 - 它会自动为您连接登录系统。

You can certainly then "add" or have more information about each user added to the logon database, but it makes ZERO sense, and I repeat ZERO sense to try and build your own logon and security system from scratch.然后,您当然可以“添加”或获得有关添加到登录数据库中的每个用户的更多信息,但这是零意义的,我重复零意义尝试从头开始构建您自己的登录和安全系统。 Since darn near every web site needs and requires a logon, then a VERY large set of built in tools and systems ALREADY exist for this purpose, and thus you spending a month or two to develop your own security and logon system is a VERY bad idea, and it will take you huge amounts of work to try and re-produce what is already made, build in, and has been created for you.由于每个网站都需要并且需要登录,因此已经为此目的存在大量内置工具和系统,因此您花费一两个月来开发自己的安全和登录系统是一个非常糟糕的主意,并且您将花费大量的工作来尝试和重新生产已经为您制作、构建和创建的内容。

there are quite a few ways to start out a web site with built in logons.有很多方法可以创建一个带有内置登录的网站。 You can choose one of many of the templates, and if you enable logons (authentication), then it will create and wire up the security system for you.您可以选择许多模板之一,如果您启用登录(身份验证),那么它将为您创建并连接安全系统。 As noted, you can then create additional tables in your database for additonal things like address, or tables for their projects and whatever the web site is eventually supposed to achieve.如前所述,然后您可以在数据库中创建额外的表,用于添加诸如地址之类的内容,或者为他们的项目创建表,以及网站最终应该实现的任何内容。

But, I high recommend you don't attempt to build your own system, when multiple built-in choices already exist, and are already built and setup for you.但是,我强烈建议您不要尝试构建自己的系统,因为已经存在多个内置选项,并且已经为您构建和设置。 It is better to spend the time learning how to use these built in systems as opposed to attempting to build and roll your own security system - that will result in huge amounts of work for you, and the results will STILL be worse and have less features then using a built in and support security model for you web site.最好花时间学习如何使用这些内置系统,而不是尝试构建和推出自己的安全系统 - 这将为您带来大量工作,结果仍然会更糟,功能更少然后为您的网站使用内置和支持的安全模型。

Web site security is a HUGE topic - beyond what can be a simple question and answer in say this forum, and requires efforts on your part.网站安全是一个巨大的话题 - 超出了这个论坛中的简单问题和答案,并且需要您的努力。

I would start out by creating a new web site application, and choose to have logons enabled, and the database(s), and all of that logon stuff will be created and wired up for you automatic.我将从创建一个新的网站应用程序开始,并选择启用登录,数据库和所有登录内容将自动为您创建和连接。 You then have to learn how it works - but that is FAR LESS work then trying to build and re-create your own security system.然后你必须了解它是如何工作的——但那是更少的工作,然后尝试构建和重新创建你自己的安全系统。

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

相关问题 Visual Studio 2019 设计页面未显示 - visual studio 2019 design page is not showing 插入和注册数据未显示在数据库表 Visual Studio 2019 中 - Insert and Registration data not show in database table visual studio 2019 如何在 Visual Studio 2015 社区中创建“基本页面” - How to create a “Basic Page” in Visual Studio 2015 community 添加新项目时,Visual Studio 2015没有“基本”页面? - Visual studio 2015 no Basic page when adding new item? 时间:2019-05-16 标签:c#sqlvisualstudio2019 - c# sql visual studio 2019 在 Visual Studio 2019 中调试时将输入重定向到 .NET Core Console App - Redirect input to .NET Core Console App on debugging in Visual Studio 2019 Visual Studio 2019 和 AWS:在执行 .NET Core 2.1 项目时“不是受支持的代码页” - Visual Studio 2019 and AWS: "not a supported code page" when doing a .NET Core 2.1 project 具有本地SQL Server数据库的Visual Studio登录页面 - Visual Studio Login Page with local SQL server database Visual Basic语法错误。 页内指令 - Visual Basic Syntax error. in page directive Visual Studio 2019 中的 SQL 查询生成器不读取 PL/SQL - SQL Query Builder in Visual Studio 2019 does not read PL/SQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM