如何从dll文件设置asp.net身份连接字符串而不是从webconfig?

时间:2015-12-14 07:27:27

标签: c# asp.net entity-framework dll asp.net-identity

m working for a company that they use dll for connection string and i尝试在ApplicationDbContext类中更改asp.net标识默认连接字符串, 我使用dll的连接类是这样的:

public class HRConnection
{       
    public string HR_con
    {
        get
        {
            return "server=192.168.1.21; database=HR; user=teamuser ; password=t123@456  ; connection timeout=30";                
        }
    }
}

ve tried to pass string like this , but it didn工作

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    string  HrConn = new HRConnection().HR_con;
    public ApplicationDbContext()
        : base(HrConn, throwIfV1Schema: false)
    {
    }
}

如何在代码中设置连接而不是从webconfig文件设置?

2 个答案:

答案 0 :(得分:0)

我解决了这个问题

public ApplicationDbContext()
        : base(new HRConnection().HR_con, throwIfV1Schema: false)
    {
    }

答案 1 :(得分:0)

首先尝试将硬编码字符串作为第一个参数传递给base。如果这样可行,那么我建议像这样定义你的字符串:

public class HRConnection
{       
    public readonly static string HR_con = "server=192.168.1.21; database=HR; user=teamuser ; password=t123@456  ; connection timeout=30";
}

并使用如下:

public ApplicationDbContext()
        : base(HRConnection.HR_con, throwIfV1Schema: false)
    {
    }
相关问题