简体   繁体   中英

How to allow the user can access his home page after longing in MVC4?

I am new one to asp.net mvc4. Now i am doing Login page. Login is working fine. Link for login is :59523/Login and //:59523/Admin/ListUsers , //:59523/Login/Changepassword these are the some other links. If i use //:59523/Admin/ListUsers this link in address bar, it is directly redirecting into that page before logging in . How to restrict a user from it. Please help me. Thanks in advance.

This is my controller code for login:

[HttpGet]

        public ActionResult Index()
        {
            return View();
        }

        //Verifying the User Name and Password using the Method
        [HttpPost]
        public ActionResult LogIn(Tbl_Users user, FormCollection remember)

You can add an Authorize attribute on your controller action level or the controller level to restrict access as follows:

Action

[Authorize]
public ActionResult ListUsers()
{
   ...
}

Controller

[Authorize]
public class AdminController : Controller
{

  ...

}

More info here:

http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute(v=vs.118).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM