我目前正在使用 Oracle 数据库开发 ASP.NET MVC 4 项目。我已经成功地在我的 Web.config 文件中添加了连接字符串,如下所示:
<add name="OracleDBConnString" connectionString="Provider=MSDAORA;Data Source=ISDQA;User ID=isd;Password=isdqa;" providerName="System.Data.OleDB" />
但是当我创建一个新项目时,它已经有一个内置的身份验证类。如何一劳永逸地修改这些类?我想更改默认值ConnString
。
这是我的模型:
public class UsersContext : DbContext
{
public UsersContext()
: base("OracleDBConnString")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
public class LoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
这是我的用户控制器:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
//I WANT TO MODIFY THIS PART
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
更新
当我更改为base("DefaultConnection")
时base("OracleDBConnString")
,出现此错误:
Server Error in '/' Application.
A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'System.Data.OleDb.OleDbConnection'. The store provider might not be functioning correctly.
请注意,我已经添加using System.Data.OleDb;
了我的使用。