小编Pau*_*els的帖子

从 .Net 应用程序访问 Azure Key Vault - 获取 DefaultAzureCredential 身份验证失败

我正在尝试将 .Net Core 3.1 应用程序连接到 Azure Key Vault。我已按照快速入门教程进行操作,但收到以下错误:

Microsoft.Extensions.Configuration.AzureAppConfiguration.KeyVaultReferenceException:'DefaultAzureCredential 身份验证失败..ErrorCode:, Key:Authentication:Twitter:ConsumerAPIKey

内部异常是:

MsalServiceException:AADSTS70002:客户端不存在或未为消费者启用

CreateHostBuilder 方法如下所示:

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                    .ConfigureAppConfiguration((hostingContext, config) =>
                    {
                        var settings = config.Build();

                        config.AddAzureAppConfiguration(options =>
                        {
                            options.Connect(settings["ConnectionStrings:AppConfig"])
                                .ConfigureKeyVault(kv =>
                                {
                                    kv.SetCredential(new DefaultAzureCredential());
                                });
                        });
                    })
                    .UseStartup<Startup>();
            });
Run Code Online (Sandbox Code Playgroud)

除了一篇与使用多个凭据相关的帖子(我不是)之外,我在网上几乎找不到对此的参考。

任何人都可以给我一个前进的方向:一些关于可能导致它的原因的线索吗?

编辑

以下似乎有效:

var defaultAzureCredentialsOptions = new DefaultAzureCredentialOptions()
{                                
    SharedTokenCacheTenantId = <tenant id>,
    SharedTokenCacheUsername = <my azure username>,
    ExcludeInteractiveBrowserCredential = false,
    ExcludeEnvironmentCredential = false,
    InteractiveBrowserTenantId = <tenant id> …
Run Code Online (Sandbox Code Playgroud)

azure azure-keyvault asp.net-core

4
推荐指数
1
解决办法
3724
查看次数

在SQL Server中使用AcceptChanges

我对在数据集中使用AcceptChanges的效果感到困惑.从我的测试中可以看出,这会强制对数据库更改进行评估,而忽略对数据库的任何约束.

任何人都可以确认是否是这种情况,或者如果没有,这与使用数据集上的更新功能有何不同?

c# sql-server ado.net

3
推荐指数
1
解决办法
1039
查看次数

TFS项目组织

我对TFS比较新,我想知道其他人在组织有很多项目的TFS吗?例如,有人知道是否可以将TFS项目放在文件夹中或者人们使用前缀/后缀?

tfs team-project

3
推荐指数
1
解决办法
2778
查看次数

用C#读取ini文件

我正在尝试读取具有以下格式的ini文件:

SETTING=VALUE 
SETTING2=VALUE2
Run Code Online (Sandbox Code Playgroud)

我目前有以下代码:

string cache = sr.ReadToEnd();                    
string[] splitCache = cache.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries);
Run Code Online (Sandbox Code Playgroud)

这给了我一个设置列表,但是,我想要做的是将其读入字典.我的问题是,有没有办法在不迭代整个数组并手动填充字典的情况下执行此操作?

c# arrays string

3
推荐指数
2
解决办法
9010
查看次数

C#错误表现

看起来捕获错误比在错误之前执行检查(例如TryParse)慢.提示观察的相关问题在这里这里.

任何人都可以告诉我为什么会这样 - 为什么捕获错误以执行一次或多次数据检查以防止错误的成本更高?

c# error-handling performance

3
推荐指数
1
解决办法
127
查看次数

添加和检索KeyedCollection

我想使用KeyedCollection来存储针对字符串键值的类.我有以下代码:

public class MyClass
{
    public string Key;
    public string Test;
}

public class MyCollection : KeyedCollection<string, MyClass>
{
    public MyCollection() : base()
    {
    }

    protected override String GetKeyForItem(MyClass cls)
    {
        return cls.Key;
    }
}

class Program
{
    static void Main(string[] args)
    {
        MyCollection col = new MyCollection();
        col.Add(new MyClass()); // Here is want to specify the string Key Value
    }
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这里我做错了什么?我在哪里指定键值,以便我可以通过它检索?

c# collections keyedcollection

3
推荐指数
1
解决办法
4644
查看次数

FtpWebRequest下载文件不正确的大小

我正在使用以下代码从远程ftp服务器下载文件:

        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);

        request.KeepAlive = true;
        request.UsePassive = true;
        request.UseBinary = true;

        request.Method = WebRequestMethods.Ftp.DownloadFile;
        request.Credentials = new NetworkCredential(userName, password);                

        using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
        using (Stream responseStream = response.GetResponseStream())
        using (StreamReader reader = new StreamReader(responseStream))
        using (StreamWriter destination = new StreamWriter(destinationFile))
        {
            destination.Write(reader.ReadToEnd());
            destination.Flush();
        }
Run Code Online (Sandbox Code Playgroud)

我正在下载的文件是一个DLL,我的问题是它以某种方式被这个过程改变了.我知道这是因为文件大小正在增加.我怀疑这部分代码是错误的:

        destination.Write(reader.ReadToEnd());
        destination.Flush();
Run Code Online (Sandbox Code Playgroud)

任何人都可以提出任何可能出错的想法吗?

c# ftp ftpwebrequest ftpwebresponse

3
推荐指数
1
解决办法
3693
查看次数

ASP.NET MasterPageFile导致错误

我正在尝试在我的网站中使用母版页.我创建了一个页面然后创建了主页.然后我添加了标签MasterPageFile ="〜/ master".我猜我需要对我的主页做一些事情,因为我现在开始收到错误:

The page contains markup that is not valid when attached to a master page
Run Code Online (Sandbox Code Playgroud)

我的主页如下:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/my.master" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
     <form id="form1" runat="server">
     <div>

     </div>
     </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我尝试删除标签,认为这可能是问题所在.谁能指出我正确的方向?

asp.net master-pages

3
推荐指数
1
解决办法
1万
查看次数

ASP MVC使用超链接控制

我有以下超链接控件:

<asp:HyperLink ID="hypTest" runat="server" NavigateUrl="~/Views/TestFolder/TestPage.aspx" >
    Text here
</asp:HyperLink>
Run Code Online (Sandbox Code Playgroud)

但它找不到页面 - 尽管页面确实存在.我得到的错误是:

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Views/TestFolder/TestPage.aspx
Run Code Online (Sandbox Code Playgroud)

我的猜测是,波浪号(〜)在这里不起作用.如果是这种情况那么为什么,我该如何解决它呢?

asp.net asp.net-mvc hyperlink

3
推荐指数
1
解决办法
2231
查看次数

代码隐藏中无法识别XAML控件

我有一个奇怪的问题,在后面的代码中看不到XAML控件.以下是XAML的示例:

<ListView Name="lvtest" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,20,0,0" 
              ItemsSource="{Binding Content}" >
    <ListView.ItemTemplate>
        <DataTemplate>     
            <StackPanel>                                
                <WebView Name="contentView" Style="{StaticResource BodyTextStyle}" />
                <TextBlock Name="testtxt" Text="{Binding}" Style="{StaticResource BodyTextStyle}" Foreground="GreenYellow"/>
Run Code Online (Sandbox Code Playgroud)

在后面的代码中:

this.lvtest 是公认的,但是:

this.contentView并且this.testtxt都不是.

我也试过了x:Name.

我显然遗漏了一些明显的东西,我只是看不出来.

编辑:

为了澄清,文本框控件将用于显示基于绑定的一些格式化文本,但我发现文本是HTML格式的(表明使用WebView控件).据我所知,我需要NavigateToString使用WebView控件,因此无法将其绑定.

c# xaml microsoft-metro winrt-xaml

3
推荐指数
1
解决办法
5836
查看次数