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
Mouhssine tahri
NA
201
11.1k
insert in database information connection user (iduser ,date , time...
Mar 9 2021 11:28 AM
Hello,
i want if a user is connected in my web application some informations (IdUser,name date .. ) are insert in my table History in database sql server.
my class table:History.cs
namespace
GEC.DATA
{
using
System;
using
System.Collections.Generic;
public
partial
class
History
{
public
int
HistoryID {
get
;
set
; }
public
string
Description {
get
;
set
; }
public
string
IpAddress {
get
;
set
; }
public
Nullable<System.DateTime> DateEvenement {
get
;
set
; }
public
Nullable<
int
> CodeUser {
get
;
set
; }
public
string
Resultat {
get
;
set
; }
public
Nullable<System.DateTime> HeureEvenement {
get
;
set
; }
}
}
my controller:
public
class
LoginController : Controller
{
[HttpPost]
public
ActionResult Login(LoginViewModel loginViewModel,
string
returnUrl)
{
var Authentifie = HttpContext.User.Identity.IsAuthenticated;
ViewData[
"Authentifie"
] = Authentifie;
if
(ModelState.IsValid)
{
User user = usersDAL.VerifyCredential(loginViewModel.LogedUser.Login, loginViewModel.LogedUser.Password);
if
(user !=
null
)
{
FormsAuthentication.SetAuthCookie(user.UserID.ToString(),
false
);
if
(!
string
.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))
return
Redirect(returnUrl);
return
Redirect(
"/"
);
}
ModelState.AddModelError(
"User.Login"
,
"Login et/ou mot de passe incorrect(s)"
);
}
return
View(loginViewModel);
}
}
my view Login.cshtml:
<div
class
=
"login-body"
>
<div
class
=
"login-title"
><strong>Bonjour</strong>, Connectez vous</div>
@using (Html.BeginForm(
null
,
null
,
new
{ ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post,
new
{ id =
"loginform"
}))
{
<div
class
=
"form-horizontal"
>
<div
class
=
"form-group"
>
<div
class
=
"col-md-12"
>
@Html.EditorFor(model => model.LogedUser.Login,
new
{ htmlAttributes =
new
{ @
class
=
"validate[required] form-control"
, placeholder =
"Username"
} })
@Html.ValidationMessageFor(model => model.LogedUser.Login,
""
,
new
{ @
class
=
"text-danger"
})
@*<input type=
"text"
class
=
"form-control"
placeholder=
"Username"
/>*@
</div>
</div>
<div
class
=
"form-group"
>
<div
class
=
"col-md-12"
>
@Html.PasswordFor(model => model.LogedUser.Password,
new
{ @
class
=
"validate[required] form-control"
, placeholder =
"Password"
})
@Html.ValidationMessageFor(model => model.LogedUser.Password,
""
,
new
{ @
class
=
"text-danger"
})
@*<input type=
"text"
class
=
"form-control"
placeholder=
"Password"
/>*@
<div
class
=
"profile-data-title"
id=
"UserId"
></div>
</div>
</div>
<div
class
=
"form-group"
>
<div
class
=
"col-md-6"
>
<a href=
"#"
class
=
"btn btn-link btn-block"
>Mot de passe oublié?</a>
</div>
<div
class
=
"col-md-6"
>
<button
class
=
"btn btn-info btn-block"
id=
"LoginId"
onclick=
"clicked();"
>Log In </button>
</div>
</div>
</div>
Html.EndForm();
}
</div>
with this example authentification in my web app works goog , but what i want if i press button id="LoginId"
with event onclick I execute my javascript function clicked(); wich allows me to insert in my database
i want only how i can get information of authentificaion in my function javascript
thanks
Reply
Answers (
2
)
cannot display image in data gridview
.Net library to manage user management with hierarchy