I have a home controller, Employee controller in mvc.
Home controller index page is login page.
Now when user tries to access Employee controller it should automatically redirect to login page that is home controller index.
I am doing it using web.config file. All working but it not redirecting to login page instead showing access denied error.
Here is the code:
<system.web>
<authentication mode="Forms">
<forms loginUrl="Home/Index" />
</authentication>
<authorization>
<deny users="*"/>
</authorization>
<location path="Home">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
In MVC, you should be using the Authorize
attribute rather than changing your web.config
. For example:
[Authorize]
public class EmployeeController : Controller
{
//snip
}
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.