ASP.NET身份:授权与角色在Azure上不起作用属性 [英] ASP.NET Identity: Authorize attribute with roles doesn't work on Azure

查看:255
本文介绍了ASP.NET身份:授权与角色在Azure上不起作用属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚出版了我的新的ASP.NET MVC Web站点身份和OWIN授权在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")]

在本地主机使用远程SQL Azure的数据库甚至当它工作正常。
但是在Azure上,以授权任何控制器加载几分钟角色属性,然后抛出:

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:

建立SQL Server的连接时发生网络相关的或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:26 - 错误定位指定的服务器/实例)

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.

推荐答案

并没有真正解决问题的Azure,最终写我自己的授权属性。这个问题似乎是在User.IsInRole()方法,所以就避免它。

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.

这篇关于ASP.NET身份:授权与角色在Azure上不起作用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆