Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor localhost and IP Issue

$
0
0

I have a big problem with which I no longer know what to do.

I have created a multilingual DevExpress XAF Blazor Server App which is working so far. When I access the site with http://localhost:8080 or http://127.0.0.1:8080 everything works fine. Cookies are set and the language can also be changed. But as soon as I access the site with http://192.168.178.200:8080 locally or via another machine, cookies are no longer set and the language can no longer be changed. The site is simply reloaded when I change the language and nothing changes.

I have already tried various approaches but none of them have worked. Perhaps someone has already had such a problem and knows what it could be.

Translated with DeepL.com (free version)

thx

Here my code:

Startup.cs

    public class Startup {    public Startup(IConfiguration configuration) {        Configuration = configuration;    }    public IConfiguration Configuration { get; }    // This method gets called by the runtime. Use this method to add services to the container.    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940    public void ConfigureServices(IServiceCollection services) {        services.AddSingleton(typeof(Microsoft.AspNetCore.SignalR.HubConnectionHandler<>), typeof(ProxyHubConnectionHandler<>));        services.AddRazorPages();        services.AddServerSideBlazor();        services.AddHttpContextAccessor();        services.AddScoped<CircuitHandler, CircuitHandlerProxy>();        services.AddXaf(Configuration, builder => {            builder.UseApplication<TestBlazorApplication>();            builder.Services.AddDevExpressServerSideBlazorPdfViewer();            builder.Modules                .AddAuditTrailXpo()                .AddCloningXpo()                .AddConditionalAppearance()                .AddDashboards(options => {                    options.DashboardDataType = typeof(DevExpress.Persistent.BaseImpl.DashboardData);                })                .AddFileAttachments()                .AddNotifications()                .AddOffice(options => options.RichTextMailMergeDataType = typeof(RichTextMailMergeData))                .AddReports(options => {                    options.EnableInplaceReports = true;                    options.ReportDataType = typeof(DevExpress.Persistent.BaseImpl.ReportDataV2);                    options.ReportStoreMode = DevExpress.ExpressApp.ReportsV2.ReportStoreModes.XML;                })                .AddScheduler()                .AddStateMachine(options => {                    options.StateMachineStorageType = typeof(DevExpress.ExpressApp.StateMachine.Xpo.XpoStateMachine);                })                .AddValidation(options => {                    options.AllowValidationDetailsAccess = false;                })                .AddViewVariants()                .Add<Test.Module.TestModule>()                .Add<TestBlazorModule>();            builder.ObjectSpaceProviders                .AddSecuredXpo((serviceProvider, options) => {                    string connectionString = null;                    if (Configuration.GetConnectionString("ConnectionString") != null)                    {                        connectionString = Configuration.GetConnectionString("ConnectionString");                    }                    ArgumentNullException.ThrowIfNull(connectionString);                    options.ConnectionString = connectionString;                    options.ThreadSafe = true;                    options.UseSharedDataStoreProvider = true;                })                .AddNonPersistent();            builder.Security                .UseIntegratedMode(options => {                    options.Lockout.Enabled = true;                    options.RoleType = typeof(Test.Module.BusinessObjects.ApplicationPermissionPolicyRole);                    // ApplicationUser descends from PermissionPolicyUser and supports the OAuth authentication. For more information, refer to the following topic: https://docs.devexpress.com/eXpressAppFramework/402197                    // If your application uses PermissionPolicyUser or a custom user type, set the UserType property as follows:                    options.UserType = typeof(Test.Module.BusinessObjects.ApplicationUser);                    // ApplicationUserLoginInfo is only necessary for applications that use the ApplicationUser user type.                    // If you use PermissionPolicyUser or a custom user type, comment out the following line:                    options.UserLoginInfoType = typeof(Test.Module.BusinessObjects.ApplicationUserLoginInfo);                    options.UseXpoPermissionsCaching();                    options.Events.OnSecurityStrategyCreated += securityStrategy => {                        // Use the 'PermissionsReloadMode.NoCache' option to load the most recent permissions from the database once                        // for every Session instance when secured data is accessed through this instance for the first time.                        // Use the 'PermissionsReloadMode.CacheOnFirstAccess' option to reduce the number of database queries.                        // In this case, permission requests are loaded and cached when secured data is accessed for the first time                        // and used until the current user logs out.                        // See the following article for more details: https://docs.devexpress.com/eXpressAppFramework/DevExpress.ExpressApp.Security.SecurityStrategy.PermissionsReloadMode.                        ((SecurityStrategy)securityStrategy).PermissionsReloadMode = PermissionsReloadMode.NoCache;                    };                })                .AddPasswordAuthentication(options => {                    options.IsSupportChangePassword = true;                });        });        var authentication = services.AddAuthentication(options => {            options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;        });        authentication.AddCookie(options => {            options.LoginPath = "/LoginPage";        });    }    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.    public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {        if(env.IsDevelopment()) {            app.UseDeveloperExceptionPage();        }        else {            app.UseExceptionHandler("/Error");            // The default HSTS value is 30 days. To change this for production scenarios, see: https://aka.ms/aspnetcore-hsts.            app.UseHsts();        }        app.UseHttpsRedirection();        app.UseRequestLocalization();        app.UseStaticFiles();        app.UseRouting();        app.UseAuthentication();        app.UseAuthorization();        app.UseXaf();        app.UseEndpoints(endpoints => {            endpoints.MapXafEndpoints();            endpoints.MapBlazorHub();            endpoints.MapFallbackToPage("/_Host");            endpoints.MapControllers();        });    }}

appsettings.json

    {"ConnectionStrings": {"ConnectionString": ""  },"Logging": {"LogLevel": {"Default": "Information","Microsoft": "Warning","Microsoft.Hosting.Lifetime": "Information","DevExpress.ExpressApp": "Information"    }  },"AllowedHosts": "*","DevExpress": {"ExpressApp": {"Languages": "de-DE;en-US;","ShowLanguageSwitcher": true,"ThemeSwitcher": {"DefaultItemName": "Blazing Dark","ShowSizeModeSwitcher": true,"Groups": [          {"Caption": "DevExpress Themes","Items": [              {"Caption": "Blazing Berry","Url": "_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css","Color": "#5c2d91"              },              {"Caption": "Blazing Dark","Url": "_content/DevExpress.Blazor.Themes/blazing-dark.bs5.min.css","Color": "#46444a"              },              {"Caption": "Office White","Url": "_content/DevExpress.Blazor.Themes/office-white.bs5.min.css","Color": "#fe7109"              },              {"Caption": "Purple","Url": "_content/DevExpress.Blazor.Themes/purple.bs5.min.css","Color": "#7989ff"              }            ]          }        ]      }    }  }}

Program.cs

    public class Program : IDesignTimeApplicationFactory {    private static bool ContainsArgument(string[] args, string argument) {        return args.Any(arg => arg.TrimStart('/').TrimStart('-').ToLower() == argument.ToLower());    }    public static int Main(string[] args) {        Tracing.LogName = "TestLogFile";        if (ContainsArgument(args, "help") || ContainsArgument(args, "h")) {            Console.WriteLine("Updates the database when its version does not match the application's version.");            Console.WriteLine();            Console.WriteLine($"    {Assembly.GetExecutingAssembly().GetName().Name}.exe --updateDatabase [--forceUpdate --silent]");            Console.WriteLine();            Console.WriteLine("--forceUpdate - Marks that the database must be updated whether its version matches the application's version or not.");            Console.WriteLine("--silent - Marks that database update proceeds automatically and does not require any interaction with the user.");            Console.WriteLine();            Console.WriteLine($"Exit codes: 0 - {DBUpdaterStatus.UpdateCompleted}");            Console.WriteLine($"            1 - {DBUpdaterStatus.UpdateError}");            Console.WriteLine($"            2 - {DBUpdaterStatus.UpdateNotNeeded}");        }        else {            DevExpress.ExpressApp.FrameworkSettings.DefaultSettingsCompatibilityMode = DevExpress.ExpressApp.FrameworkSettingsCompatibilityMode.Latest;            DevExpress.ExpressApp.Security.SecurityStrategy.AutoAssociationReferencePropertyMode = DevExpress.ExpressApp.Security.ReferenceWithoutAssociationPermissionsMode.AllMembers;            IHost host = CreateHostBuilder(args).Build();            if(ContainsArgument(args, "updateDatabase")) {                using(var serviceScope = host.Services.CreateScope()) {                    return serviceScope.ServiceProvider.GetRequiredService<DevExpress.ExpressApp.Utils.IDBUpdater>().Update(ContainsArgument(args, "forceUpdate"), ContainsArgument(args, "silent"));                }            }            else {                host.Run();            }        }        return 0;    }    public static IHostBuilder CreateHostBuilder(string[] args) =>        Host.CreateDefaultBuilder(args)            .ConfigureWebHostDefaults(webBuilder => {                webBuilder.UseStartup<Startup>();            });    XafApplication IDesignTimeApplicationFactory.Create() {        IHostBuilder hostBuilder = CreateHostBuilder(Array.Empty<string>());        return DesignTimeApplicationFactoryHelper.Create(hostBuilder);    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>