小编Ben*_*eld的帖子

Dotnet Core 2.1 中的主题 RazorPages

我目前正在尝试在 dotnetcore 2.1 中使用 Razor Pages 实现一个主题化网站,但我对页面无法加载的原因有一些麻烦/困惑。

对站点的每个请求都会导致根据访问的域设置主题值,默认情况下,主题是“默认”,它存储在每个请求的 RouteData 中。

我已经实施了以下 ThemeViewLocationExpander

public class ThemeViewLocationExpander : IViewLocationExpander
{
    private const string ValueKey = "Theme";

    public void PopulateValues(ViewLocationExpanderContext context)
    {
        if (context is null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        context.Values[ValueKey] = (context.ActionContext.RouteData.Values["tenant"] as Tenant)?.Theme;
    }

    public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
    {
        if (context is null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        if (viewLocations is null)
        {
            throw new ArgumentNullException(nameof(viewLocations));
        }

        context.Values.TryGetValue(ValueKey, out string theme);

        if (!string.IsNullOrEmpty(theme))
        {
            viewLocations = new[] { …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc multi-tenant .net-core razor-pages

7
推荐指数
0
解决办法
1111
查看次数

使用 .NET Core 2.1 配置企业库

我正在将解决方案从 .NET Framework 4.7.1 迁移到 .NET Core 2.1,并且遇到了 Enterprise Library 6 的问题(使用 EnterpriseLibrary.Data.NetCore Nuget Package)

我正在尝试从连接字符串创建数据库并将其注册到 Autofac。

原始代码如下所示:

builder.Register(c => new DatabaseProviderFactory().Create(DefaultConnection) as SqlDatabase).InstancePerLifetimeScope();
Run Code Online (Sandbox Code Playgroud)

其中DefaultConnection是表示连接字符串的字符串常量web.config

web.config我有:

<configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="DefaultConnection" />
<connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="*****************" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

这很好用。

在我的 .NET Core 2.1 解决方案中,我使用以下代码

builder.Register(_ => new DatabaseProviderFactory().Create(Constants.DefaultConnection) as SqlDatabase).InstancePerLifetimeScope();
Run Code Online (Sandbox Code Playgroud)

但这会引发以下异常:

The connection string for the database 'DefaultConnection' does not exist or does not have a valid provider. …
Run Code Online (Sandbox Code Playgroud)

c# migration enterprise-library asp.net-core-mvc asp.net-core

5
推荐指数
0
解决办法
2217
查看次数