小编Nic*_*ick的帖子

在长期存在的实体框架上下文中刷新Sql连接Azure AD访问令牌

我正在尝试设置一些.NET应用程序,以便对Azure Active Directory使用基于证书的身份验证,然后使用Active Directory授权我访问Sql Azure数据库.

我遇到的问题是应用程序的某些部分使用的DbContext可能有点太长.如果您在访问令牌到期后的5分钟内请求访问令牌,则ADAL库会尝试刷新访问令牌.麻烦的是我的一些DbContexts可能活超过5分钟.因此,在DbContext的生命周期中,访问令牌不再好,当我尝试SaveChanges时,我得到一个数据库连接异常.

除了重构使我的DbContexts活动时间短于5分钟,我还能做些什么来解决这个问题吗?

我尝试过的一件事是在实体框架中找到一些钩子,我可以捕获过期的访问令牌异常,然后用新创建的具有新访问令牌的连接替换当前连接.我尝试传递EF自定义连接工厂,然后使用执行策略在我收到过期令牌异常时重试.这对我不起作用,因为我无法从自定义执行策略修改或重新创建当前连接.

任何想法将不胜感激.

谢谢!

c# entity-framework dbcontext azure-active-directory adal

11
推荐指数
1
解决办法
816
查看次数

Firefox中的SVG过滤器

出于某种原因,我无法让我的SVG过滤器在Firefox中运行.但是,它们在Opera中运行良好.我设置为过滤器的属性刚刚消失的元素.这很奇怪.

这是我的javascript代码:

defsElement = SVGDoc.createElement("defs");
var filterElement = SVGDoc.createElement("filter");
filterElement.setAttribute( "id", "cm-mat");
filterElement.setAttribute( "filterUnits", "objectBoundingBox");

var fecolormatrixElement = SVGDoc.createElement("feColorMatrix");
fecolormatrixElement.setAttribute("type", "matrix");
fecolormatrixElement.setAttribute("in", "SourceGraphic");
fecolormatrixElement.setAttributeNS(null, "values", "1 1 1 1 1  2 2 2 2 1  1 1 1 1 1  1 1 1 1 1");
filterElement.appendChild(fecolormatrixElement);
defsElement.appendChild(filterElement);
SVGDoc.documentElement.insertBefore(defsElement, SVGDoc.documentElement.childNodes.item(1));

partRef = getElementFromID(SVGDoc.documentElement, part);
if(partRef != null)
{
    partRef.style.setProperty('filter', 'url(#cm-mat)', null);
}
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?谢谢

javascript firefox svg dom svg-filters

5
推荐指数
1
解决办法
2451
查看次数

远程桌面不适用于 Windows Azure 云服务。“在角色中发现了旧插件 RemoteAccess”

我正在尝试发布 Azure 云服务,但我不断收到此错误 - 'Legacy plugin RemoteAccess is found in role 。请从服务定义文件中删除导入以使用扩展。

我的 csdef 中有以下几行 -

 <Import moduleName="RemoteAccess" />
 <Import moduleName="RemoteForwarder" />
Run Code Online (Sandbox Code Playgroud)

以及我的 cscfg 中的以下几行 -

<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
 <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" value="username" />
 <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" value="password" />
 <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" value="2016-06-03T23:59:59.0000000-07:00" />
 <Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
Run Code Online (Sandbox Code Playgroud)

 <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="thumbprint" thumbprintAlgorithm="sha1" />
Run Code Online (Sandbox Code Playgroud)

从我读过的内容来看,这应该足够了。我也没有发现任何关于“远程访问”插件被弃用的信息。

我也尝试删除这些行并发布 - 工作正常,但我无法使用远程桌面。我收到错误消息“指定的用户名不存在。请验证用户名并再次尝试登录。如果问题仍然存在,请联系您的系统管理员或技术支持。” 尝试登录时。

remote-desktop azure visual-studio

5
推荐指数
1
解决办法
3885
查看次数

使用Autofac解析对象时,即使使用ConfigurationAwait(false)也会在Async上死锁

即使我正在使用ConfigureAwait(false),我在某些C#代码上遇到了死锁.不幸的是我无法一直使用异步,因此我依赖于ConfigureAwait.

情况是我需要发出HTTP请求,以便在启动Web应用程序和控制台应用程序期间从Azure AD检索数据库访问令牌.在这两种情况下,当Autofac尝试解析触发Web请求的数据库令牌时,程序会死锁.奇怪的是它可以工作两次但第三次失败.

Autofac模块:

 public class AzureActiveDirectoryModule : BaseModule
 {
    protected override bool SupportsMultipleModuleRegistrations => true;

    protected override void Load(ContainerBuilder builder)
    {
        builder.RegisterType<AzureActiveDirectoryService>().As<IAzureActiveDirectoryService>();

        builder.Register(c => c.Resolve<IAzureActiveDirectoryService>().GetAuthenticationContext())
               .As<AuthenticationContext>()
               .SingleInstance();

        builder.Register(c => c.Resolve<IAzureActiveDirectoryService>().GetCertificateCredential())
               .As<ClientAssertionCertificate>()
               .SingleInstance();

        builder.Register(c =>
                         c.Resolve<IAzureActiveDirectoryService>()
                          .GetDatabaseAccessToken(c.Resolve<AuthenticationContext>(), c.Resolve<ClientAssertionCertificate>()))
               .Named<string>(PersistenceModule.DatabaseAccessToken);
    }
}
Run Code Online (Sandbox Code Playgroud)

发出HTTP请求的服务(我通过调用google替换了http请求):

public class AzureActiveDirectoryService : IAzureActiveDirectoryService
{

    public string GetDatabaseAccessToken(AuthenticationContext authContext, ClientAssertionCertificate certCred)
    {
        try
        {
            return AcquireDatabaseToken(certCred, authContext).Result;
        }
        catch (Exception ex)
        {
            Log.Error(ex, "Exception occurred while attempting to retrieve database access token.");
        }

        return string.Empty;
    }

    private …
Run Code Online (Sandbox Code Playgroud)

c# deadlock dependency-injection async-await

0
推荐指数
1
解决办法
505
查看次数