Click here to Skip to main content
15,312,353 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to implement Authentication and Authorization in MVC?

I have used it as-

public ActionResult Default()
{
if (Session["UserId"] == null)
{
Session.Abandon();

return RedirectToAction("Login", "Login");
}
else
{
return View();
}
}

After successfully logging, redirects on Home controller and action - Default.
Here i am check session userid value if it is null then go to Login controller and invoke login method.

I know that in mvc there is a attribute named as Authenticate but i am not aware how to use it.

Plz give me solution and code.


Thanks..
Ashish
Posted
Updated 16-Oct-14 0:06am
v2
Comments
Nathan Minier 16-Oct-14 7:15am
   
The attribute you want is the AuthorizeAttribute, not AuthenticateAttribute.

Google will yield you much, if you know what you're looking for.
Sinisa Hajnal 16-Oct-14 7:22am
   
Google it. Never ask for finished code - if you show / describe what you tried we'll help with some particular problem. Getting the code handed to you will make you lazy, dependant on others and all around bad developer. Developers solve problems. They turn to others after extensive research, not after first stop!
AshishvermaMCA 20-Oct-14 7:40am
   
Thanks

1 solution

   
Comments
AshishvermaMCA 20-Oct-14 7:40am
   
Thanks to all of you!!

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