我检查了这个网站,但没有找到任何解决方案。我用mvc4做了一个网站。我写了自定义数据实体。但是,该应用程序在 localhost 上运行良好,但我无法在远程服务器上使用它。
这是我的配置 web.config 连接字符串
<add name="DefaultConnection" connectionString="Data Source=ipaddress;Initial Catalog=DataContext;User ID=user;Password=pass" providerName="System.Data.SqlClient" />
这是我的数据上下文。这会在本地 sql server 中创建新的数据库。如何使用此设置使用远程服务器?
public class DataContext : DbContext
{
public DbSet<Sayfalar> sayfa { get; set; }
public DbSet<Uyeler> uye { get; set; }
public DbSet<Roller> rol { get; set; }
public DbSet<Loglar> log { get; set; }
public DbSet<Resimler> resim { get; set; }
}
class dbYenile : DropCreateDatabaseIfModelChanges<DataContext>
{
protected override void Seed(DataContext context)
{
MembershipCreateStatus Durum = new MembershipCreateStatus();
Membership.CreateUser("demo", "123456", "demo@demo.com", "soru", "cevap", true, out Durum);
Durum = new MembershipCreateStatus();
Membership.CreateUser("demo1", "123456", "demo1@demo.com", "soru", "cevap", true, out Durum);
Roles.CreateRole("Yonetici");
Roles.AddUsersToRoles(new string[] { "demo" }, new string[] { "Yonetici" });
//Console.WriteLine(Hatalar.uyelikHatalari(Durum));
}
}
这里 Global.asax.cs 的 application_start 无效。
Database.SetInitializer<DataContext>(new dbYenile());
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();