小编Dol*_*ead的帖子

MAUI:appsettings.json 的构建操作是什么以及如何在 Android 上访问该文件?

.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)

样机项目在这里

c# maui .net-6.0

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

SignalR 与 JS 客户端上的 accessTokenFactory 的连接无法与 connectionId 和 UserIdentifier 连接,但 .Net 客户端没问题

在我的 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)

c# jwt signalr asp.net-core

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

标签 统计

c# ×2

.net-6.0 ×1

asp.net-core ×1

jwt ×1

maui ×1

signalr ×1