Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP MVC Authorize Error

When I Use :

[Authorize]
public ActionResult Index() {
    ....
    return View();
}

OR

[Authorize(Users="john")]
public ActionResult Index() {
    ....
    return View();
}

My Script Working Well But When I Use :

[Authorize(Roles="Admin")]
public ActionResult Index() {
    .....
    return View();
}

Error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified).

like image 401
user3568804 Avatar asked Apr 24 '14 12:04

user3568804


People also ask

How do I Authorize in MVC?

Authorization in MVC is controlled through the AuthorizeAttribute attribute and its various parameters. At its simplest applying the AuthorizeAttribute attribute to a controller or action limits access to the controller or action to any authenticated user.

What is Authorize in ASP NET MVC?

In MVC, the 'Authorize' attribute handles both authentication and authorization. In general, it works well, with the help of extension to handle AJAX calls elegantly, and to distinguish between unauthorized users and those who are not logged in.

What does Authorize attribute do C#?

Web API provides a built-in authorization filter, AuthorizeAttribute. This filter checks whether the user is authenticated. If not, it returns HTTP status code 401 (Unauthorized), without invoking the action. We can apply the filter globally, at the controller level, or at the level of individual actions.

What is Authorize in asp net?

Authorization refers to the process that determines what a user is able to do. For example, an administrative user is allowed to create a document library, add documents, edit documents, and delete them. A non-administrative user working with the library is only authorized to read the documents.


1 Answers

I found a solution. In my web.config:

1.<modules>
2.<remove name="FormsAuthenticationModule" />
3.<remove name="RoleManager" />
4.</modules>

I added the line 3, and the new AspNet.Identity code took over allowing me to use User.IsInRole(..)

like image 119
Mohammad Javad Avatar answered Sep 23 '22 17:09

Mohammad Javad