7

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).

5
  • Is this using AspNet.Indentity? Commented Apr 24, 2014 at 12:45
  • Yes Microsoft.AspNet.Identity.EntityFramework Commented Apr 24, 2014 at 12:49
  • You have a sql server connection problem. not related to Authorize. Commented Apr 24, 2014 at 13:25
  • Can u show your DbConext and web config? Commented Apr 24, 2014 at 13:27
  • possible duplicate of SimpleMembership, MVC4, AuthorizeAttribute and Roles Commented Apr 24, 2014 at 13:28

1 Answer 1

11

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(..)

Sign up to request clarification or add additional context in comments.

1 Comment

It helped me a lot, thanks. Do you know why is this required? I downloaded the sample for Identity from NuGet and there is no such code in Web.config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.