Click here to Skip to main content
15,891,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
supposre student can acces student url and teacher can access teacher url if student paste the url directy he is able to go ito the teachers the page..how to restrict


how to rstrict the user that when he paste the teachers url it will redirect him to login page and vise versa
Posted
Comments
Sinisa Hajnal 28-Jan-16 2:40am    
Have them login before they can access anything. If the user is not autheniticated, you redirect him to login page. After the login, you know who he is and can set the access rights.

Google "form authentification in mvc".
Member 11970398 28-Jan-16 2:45am    
yeah i know that but only i have t write it web.config file or some where else

1 solution

You're looking at the difference between Authentication and Authorization. What you're looking for is two things, first off using a Role Provider, and secondly using the AuthorizeAttribute.

The MS guidance on role Providers is here:
Implementing a Role Provider[^]

There is an article on CP that describes one possible implementation here:
ASP.NET MVC 5 Identity: Extending and Modifying Roles[^]

And finally, once you have a role provider, you can lock down items by controller or by action with the AuthorizeAttribute:
C#
[Authorize(Roles="Admin,User")]
public class AccountController : Controller
{
   [Authorize(Roles="Admin")]
   public ActionResult DeleteAccount(){...}

}
 
Share this answer
 

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