.Host.ConfigureAppConfiguration我为 MAUI 应用程序创建了一个 appsettings 文件,并使用MauiApp.CreateBuilder(); 的构建器将其加载到 IConfiguration 中;我可以在 Windows 中访问该文件,但在运行 Android 模拟器时则无法访问。代码:
var builder = MauiApp.CreateBuilder();
builder
.RegisterBlazorMauiWebView()
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
})
.Host
.ConfigureAppConfiguration((app, config) =>
{
#if __ANDROID__
// /sf/ask/3490731191/
//var documentsFolderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
config.AddJsonFile( "appsettings.json", optional: false, reloadOnChange: true);
#endif
#if WINDOWS10_0_17763_0_OR_GREATER
///sf/ask/4830033211/
Assembly callingAssembly = Assembly.GetEntryAssembly();
Version versionRuntime = callingAssembly.GetName().Version;
string assemblyLocation = Path.GetDirectoryName(System.AppContext.BaseDirectory); //CallingAssembly.Location
var configFile = Path.Combine(assemblyLocation, "appsettings.json");
config.AddJsonFile(configFile, optional: false, reloadOnChange: true);
#endif
});
Run Code Online (Sandbox Code Playgroud)
样机项目在这里
在我的 SignalR 身份验证原型中,JS 客户端没有 Context.UserIdentifier,当连接到 JS 客户端的 SignalR 集线器时,connectionId 将为 0。它与 .NET 客户端配合良好。
想知道构建连接是否错误?这是我的连接:
state.connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub", {
accessTokenFactory: async () => {
axios.post('https://localhost:44384/api/account/token', { email: email, password: password })
.then(async (response) => {
if (typeof response === 'undefined') {
return;
}
else {
console.log(response.data);
console.log(state.connection.id);
return response.data;
}
})
.catch((error) => {
console.log(error);
});
}
})
.build();
Run Code Online (Sandbox Code Playgroud)
WPF 客户端使用以下代码可以很好地连接令牌:
_connection = new HubConnectionBuilder()
.WithUrl("https://localhost:44384/ChatHub", options =>
{
options.AccessTokenProvider = async () =>
{
var tokenUserCommand = new …Run Code Online (Sandbox Code Playgroud)