我正在尝试将 .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) 我对在数据集中使用AcceptChanges的效果感到困惑.从我的测试中可以看出,这会强制对数据库更改进行评估,而忽略对数据库的任何约束.
任何人都可以确认是否是这种情况,或者如果没有,这与使用数据集上的更新功能有何不同?
我对TFS比较新,我想知道其他人在组织有很多项目的TFS吗?例如,有人知道是否可以将TFS项目放在文件夹中或者人们使用前缀/后缀?
我正在尝试读取具有以下格式的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)
这给了我一个设置列表,但是,我想要做的是将其读入字典.我的问题是,有没有办法在不迭代整个数组并手动填充字典的情况下执行此操作?
我想使用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)
谁能告诉我这里我做错了什么?我在哪里指定键值,以便我可以通过它检索?
我正在使用以下代码从远程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)
任何人都可以提出任何可能出错的想法吗?
我正在尝试在我的网站中使用母版页.我创建了一个页面然后创建了主页.然后我添加了标签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: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)
我的猜测是,波浪号(〜)在这里不起作用.如果是这种情况那么为什么,我该如何解决它呢?
我有一个奇怪的问题,在后面的代码中看不到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# ×6
asp.net ×2
ado.net ×1
arrays ×1
asp.net-core ×1
asp.net-mvc ×1
azure ×1
collections ×1
ftp ×1
hyperlink ×1
master-pages ×1
performance ×1
sql-server ×1
string ×1
team-project ×1
tfs ×1
winrt-xaml ×1
xaml ×1