Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Friends -
Here is a simple .aspx file I got somewhere on the net.
__________________________________________________________

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>




<title>

body
{
font-family: Arial;
font-size: 10pt;
}
input
{
width: 200px;
}
table
{
border: 1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}





Registration
Username
<asp:textbox id="txtUsername" runat="server">
<asp:requiredfieldvalidator errormessage="Required" forecolor="Red" controltovalidate="txtUsername"
="" runat="server">
Password
<asp:textbox id="txtPassword" runat="server" textmode="Password">
<asp:requiredfieldvalidator errormessage="Required" forecolor="Red" controltovalidate="txtPassword"
="" runat="server">
Confirm Password
<asp:textbox id="txtConfirmPassword" runat="server" textmode="Password">
<asp:comparevalidator errormessage="Passwords do not match." forecolor="Red" controltocompare="txtPassword"
="" controltovalidate="txtConfirmPassword" runat="server">
Email
<asp:textbox id="txtEmail" runat="server">
<asp:requiredfieldvalidator errormessage="Required" display="Dynamic" forecolor="Red"
="" controltovalidate="txtEmail" runat="server">
<asp:regularexpressionvalidator runat="server" display="Dynamic" validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
="" controltovalidate="txtEmail" forecolor="Red" errormessage="Invalid email address.">
<asp:button text="Submit" runat="server" onclick="RegisterUser">





__________________________________________
Here is the Code behind C# Code.
__________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class CS : System.Web.UI.Page
{
protected void RegisterUser(object sender, EventArgs e)
{
int userId = 0;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Insert_User"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Username", txtUsername.Text.Trim());
cmd.Parameters.AddWithValue("@Password", txtPassword.Text.Trim());
cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim());
cmd.Connection = con;
con.Open();
userId = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
}
string message = string.Empty;
switch (userId)
{
case -1:
message = "Username already exists.\\nPlease choose a different username.";
break;
case -2:
message = "Supplied email address has already been used.";
break;
default:
message = "Registration successful.\\nUser Id: " + userId.ToString();
break;
}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
}
}
___________________________________________
Here is the Stored Procedure
____________________________

--Insert_User 'Mudassar2', '12345', 'mudassar@aspsnippets.com'
ALTER PROCEDURE [dbo].[Insert_User]
@Username NVARCHAR(20),
@Password NVARCHAR(20),
@Email NVARCHAR(30)
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS(SELECT UserId FROM Users WHERE Username = @Username)
BEGIN
SELECT -1 -- Username exists.
END
ELSE IF EXISTS(SELECT UserId FROM Users WHERE Email = @Email)
BEGIN
SELECT -2 -- Email exists.
END
ELSE
BEGIN
INSERT INTO [Users]
([Username]
,[Password]
,[Email]
,[CreatedDate])
VALUES
(@Username
,@Password
,@Email
,GETDATE())

SELECT SCOPE_IDENTITY() -- UserId
END
END
____________________________________

What I have tried:

I tried in Local server which works well - but not in Godaddy webhost which gives error:
I tested with other simple database connection which works well. I am unable to fix this Parameter incorrect error.

The parameter is incorrect
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The parameter is incorrect


How to solve this - Please help.
Posted
Updated 17-Apr-21 3:18am
Comments
Richard Deeming 19-Apr-21 6:02am    
That code is storing users' passwords in plain text. Don't do that!

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

ASP.NET has several perfectly good libraries which handle this sort of thing for you, so there's no need to reinvent the wheel. For example, ASP.NET Identity[^].

Quote:
Here is a simple .aspx file I got somewhere on the net.

So go back to "somewhere" and ask there: we didn't write the code, so we know as much about it as you do - less probably, since you presumably know what it does if not how and we don't even have that!
 
Share this answer
 
Comments
Patrice T 17-Apr-21 9:34am    
S2 is a message for you.
Thanks OriginalGriff,
Good suggestion.
This is a problem with Godaddy webhost, they were doing some internal process when I was struggling with this code on their server. I know the code works well.
The problem was solved when they reset the Database and gave proper IP address for SQL Server. I used "that" IP address and the code works wonderful.
 
Share this answer
 
Comments
Patrice T 17-Apr-21 9:34am    
You should accept your solution, it close the question as solved.
Richard Deeming 19-Apr-21 6:01am    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution and post a comment.

Do not post your comment as a new "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900