Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Identity: Authorize attribute with roles doesn't work on Azure

I just published my new ASP.NET MVC web site with Identity and OWIN authorization on Azure. Front-end works great, but got a problem with back-end. I use [Authorize] attribute with my admin controllers to check if user has a required role to access it, like this:

[Authorize(Roles = "Admin")]

On localhost even when using remote Azure SQL database it works fine. But on Azure, any controller with authorize attribute with roles loading several minutes and then throws:

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)

Authorize attribute without roles works fine.

like image 502
Wonder Avatar asked May 29 '14 19:05

Wonder


2 Answers

Adding this code to the web.config fixes the issue.

<system.webServer>
    <modules>
        <remove name="RoleManager" />
    </modules>
</system.webServer>

I know this is late now but I have a real answer for you. Thought I'd share it anyway as I just wasted a few hours on it myself.

Info found from this post

like image 189
Robert Avatar answered Sep 30 '22 05:09

Robert


Didn't really solve the Azure problem, ended up writing my own Authorization attribute. The problem seems to be in User.IsInRole() method, so just avoid it.

like image 24
Wonder Avatar answered Sep 30 '22 04:09

Wonder