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
vishnu vishnu
NA
287
8.9k
Form Athentication(mutliple contoller not working)
Aug 16 2019 11:32 PM
Hi i have Created form athentciation
<
authentication
mode
=
"Forms"
>
<
forms
loginUrl
=
"~/Home/Index"
timeout
=
"2880"
enableCrossAppRedirects
=
"false"
/>
</
authentication
>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
using
System.Web.Security;
namespace
Role_Menu_MVC.Controllers
{
public
class
HomeController : Controller
{
[AllowAnonymous]
public
ActionResult Index()
{
return
View();
}
[AllowAnonymous]
public
ActionResult Index1()
{
return
View();
}
[Authorize]
public
ActionResult Profile()
{
return
View();
}
[HttpPost]
[AllowAnonymous]
public
ActionResult Index(User user)
{
UsersEntities usersEntities =
new
UsersEntities();
RoleUser roleUser = usersEntities.ValidateUser(user.Username, user.Password).FirstOrDefault();
string
message =
string
.Empty;
switch
(roleUser.UserId.Value)
{
case
-1:
message =
"Username and/or password is incorrect."
;
break
;
case
-2:
message =
"Account has not been activated."
;
break
;
default
:
FormsAuthenticationTicket ticket =
new
FormsAuthenticationTicket(1, user.Username, DateTime.Now, DateTime.Now.AddMinutes(2880), user.RememberMe, roleUser.Roles, FormsAuthentication.FormsCookiePath);
string
hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie =
new
HttpCookie(FormsAuthentication.FormsCookieName, hash);
FormsAuthentication.SetAuthCookie(user.Username,
true
);
if
(ticket.IsPersistent)
{
cookie.Expires = ticket.Expiration;
}
Response.Cookies.Add(cookie);
if
(!
string
.IsNullOrEmpty(Request.Form[
"ReturnUrl"
]))
{
return
RedirectToAction(Request.Form[
"ReturnUrl"
].Split(
'/'
)[2]);
}
else
{
return
RedirectToAction(
"Index"
,
"Profile"
);
}
}
ViewBag.Message = message;
return
View(user);
}
[HttpPost]
[Authorize]
public
ActionResult Logout()
{
FormsAuthentication.SignOut();
return
RedirectToAction(
"Index"
);
}
}
}
[Authorize]
public
class
AdminController : Controller
{
// GET: Admin
[HttpPost]
public
ActionResult Index()
{
return
View();
}
}
i am truy to navigate <li>@Html.ActionLink("Admin", "Index")</li>
but its going to login page
please help naviagation with html link not working .when click anther controller
Reply
Answers (
1
)
console application web api using get and post method exampl
ASP,NET MVC View errors