TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
SECO DMS
NA
24
779
Registration Implementation asp.net Web Form
Nov 15 2020 10:30 AM
this is my class code
namespace
SECODMS.Model {
public
class
ApplicationUser {
public
string
UserName {
get
;
set
; }
public
string
FirstName{
get
;
set
; }
public
string
LastName {
get
;
set
; }
public
string
Email {
get
;
set
; }
public
string
AvatarUrl {
get
;
set
; }
}
public
static
class
AuthHelper {
public
static
bool
SignIn(
string
userName,
string
password) {
HttpContext.Current.Session[
"User"
] = CreateDefualtUser();
// Mock user data
return
true
;
}
public
static
void
SignOut() {
HttpContext.Current.Session[
"User"
] =
null
;
}
public
static
bool
IsAuthenticated() {
return
GetLoggedInUserInfo() !=
null
;
}
public
static
ApplicationUser GetLoggedInUserInfo()
{
return
HttpContext.Current.Session[
"User"
]
as
ApplicationUser;
}
private
static
ApplicationUser CreateDefualtUser() {
return
new
ApplicationUser {
UserName =
"vvnbnbnb"
,
FirstName =
"Julia"
,
LastName =
"Bell"
,
Email =
"
[email protected]
"
,
AvatarUrl =
"~/Content/Photo/Julia_Bell.jpg"
};
}
}
using
System;
using
DevExpress.Web;
using
SECODMS.Model;
using
System.Configuration;
using
System.Data;
using
System.Data.SqlClient;
namespace
SECODMS {
public
partial
class
SignInModule: System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
SignInButton_Click(
object
sender, EventArgs e) {
FormLayout.FindItemOrGroupByName(
"GeneralError"
).Visible =
false
;
if
(ASPxEdit.ValidateEditorsInContainer(
this
)) {
// DXCOMMENT: You Authentication logic //
string
mainconn = ConfigurationManager.ConnectionStrings[
"SECODMSConnectionString"
].ConnectionString;
SqlConnection sqlconn =
new
SqlConnection(mainconn);
string
sqlquery =
"Select * from Users where Username=@Username and Password=@Password"
;
SqlCommand sqlcomm =
new
SqlCommand(sqlquery, sqlconn);
sqlconn.Open();
sqlcomm.Parameters.AddWithValue(
"@Username"
, UserNameTextBox.Text);
sqlcomm.Parameters.AddWithValue(
"@Password"
, PasswordButtonEdit.Text);
SqlDataAdapter sda =
new
SqlDataAdapter(sqlcomm);
DataTable dt =
new
DataTable();
sda.Fill(dt);
sqlcomm.ExecuteNonQuery();
if
(dt.Rows.Count > 0) {
Session[
"user"
] = UserNameTextBox;
Response.Redirect(
"~/Default.aspx"
);
}
else
{}
if
(!AuthHelper.SignIn(UserNameTextBox.Text, PasswordButtonEdit.Text)) {
GeneralErrorDiv.InnerText =
"Invalid login attempt."
;
FormLayout.FindItemOrGroupByName(
"GeneralError"
).Visible =
true
;
}
else
Response.Redirect(
"~/Default.aspx"
);
}
}
}
}
and this my sign in code kindly advise me what's wrong I am not able to, getting the value from the session and then casting as ApplicationUser.
Reply
Answers (
3
)
Static Website Hosting with ASP.NET C# and AWS S3 problem
How to show active records in one tab and inactive records in another