Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
2.11/5 (2 votes)
See more:
Hi

I want to implement Authentication/authorization in my project

For cross browser and mobile access we are implementing web api in our project.

For View we are using normal controller.For data we are using api controller

So how can i achieve role based access and authorization in asp.net mvc 5.


I have added authentication tag in web.config
When i run application im getting follwing error

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Cod: 0x800700b7
Thanks
Syed Khaleel
Posted
Updated 5-Mar-14 19:56pm
v6

MVC5 follows the same old authentication modes as MVC4.But when in Web.cofig file you change the
C#
<authentication mode="none" />to <authentication mode="form" /> 

its stops working.

So to solve this issue add

Response.SuppressFormsAuthenticationRedirect = true
in the prescribed class.Normally authentication mode is set to none ,but in case you change you can resolve.

What the Response.SuppressFormsAuthenticationRedirect does is

Quote:
Gets or sets a value that specifies whether forms authentication redirection to the login page should be suppressed.


MVC5 does support both OpenID and Forms authentications.
Hope this helps..
Accept if you find value in this..
Happy Coding SD's :)

 
Share this answer
 
v2
Comments
[no name] 6-Mar-14 9:21am    
where should i place Response.SuppressFormsAuthenticationRedirect=true
C#
public void ProcessRequest(HttpContext context)
{
    Response.StatusCode = 401;
    Response.StatusDescription = "Authentication required";
    Response.SuppressFormsAuthenticationRedirect = true;
}

try this...in the controller else place it in the method itself.
 
Share this answer
 
Comments
[no name] 10-Mar-14 4:33am    
please can you provide me a sample example on this

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