Ok, sau khi giải pháp họ gợi lên ở đây: http://forums.asp.net/p/997608/2209437.aspx
Tôi tạo ra một lớp học trong đó, các nhà xây dựng parameterless (mà bạn cần) chỉ nhận được máy chủ và cổng từ các đối số dòng lệnh. Như vậy mà tôi có thể đi "MembershipInitializer.exe "SomeSqlServer \ Instance" 51000.
public class CustomSQLMembershipProvider : SqlMembershipProvider {
private readonly string _server;
private readonly string _port;
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Web.Security.SqlMembershipProvider"/> class.
/// </summary>
public CustomSQLMembershipProvider() {
string[] args = System.Environment.GetCommandLineArgs();
// args[0] is the exe name
_server = args[1];
_port = args[2];
}
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
base.Initialize(name, config);
// Update the private connection string field in the base class.
string connectionString = string.Format(@"Data Source={0},{1};Initial Catalog=aspnetdb;UID=NICCAMembership;PWD=_Password1;Application Name=NICCA;Connect Timeout=120;", _server, _port);
// Set private property of Membership provider.
FieldInfo connectionStringField = GetType().BaseType.GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
connectionStringField.SetValue(this, connectionString);
}
}
Trong app.config của ứng dụng giao diện điều khiển của bạn (hoặc cửa sổ ứng dụng)
<configuration>
<connectionStrings>
<clear/>
<add name="MembershipDB"
connectionString="Some Bogus String here that gets overrided in the custom class"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<authentication mode="Forms"/>
<authorization>
<deny users="?"/>
</authorization>
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
connectionStringName="MembershipDB"
applicationName="NICCA"
type="MyInitializeMembershipDB.CustomSQLMembershipProvider, MyInitializeMembershipDB"
requiresUniqueEmail="false"
requiresQuestionAndAnswer="false"/>
</providers>
</membership>
</system.web>
</configuration>
Nếu bạn đang cần các nhà cung cấp vai trò bit là tốt, bạn có thể phải ghi đè lên SqlRoleProvider theo cách tương tự.
Nếu bạn đang tạo một chương trình tự động khởi tạo cơ sở dữ liệu thành viên của bạn đến một nhà nước cụ thể nhưng địa chỉ máy chủ sql và tên cổng aren ' t được biết cho đến khi ai đó nhập chúng vào stall wizard, thao tác này sẽ thực hiện thủ thuật ..
Điều này có hữu ích không?
Đó là khá nhiều những gì tôi đã đến cuối cùng. Đó là một sự xấu hổ mà chúng tôi buộc phải sử dụng sự phản ánh để thiết lập các thành viên tư nhân để có được điều này để làm việc :-( –
Trên thực tế có một cách đơn giản hơn để thiết lập trường này: juste write config ["connectionString"] = yourConnectionString; base.Initialize (tên, cấu hình); gọi và bạn đã hoàn tất!;) – jpatte