0

我正在使用 C# 和 SQL Server 2005 开发一个 ASP .Net MVC 3 应用程序。我也在使用实体框架和代码优先方法。

我有一个用于登录(连接)的接口,但它与我有一个 USER 表(包含登录名 + 密码)的基础无关。

问题是我无法改变连接方式。准确地说,我希望连接将与我的基地有关。

这很困难,因为我使用实体框架和代码优先方法。

有什么解决办法吗?

这是我的查看登录:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage"%>
    <p>

        S'il vous plaît entrer votre Login et Mot de Passe pour vous connecter :
    </p>
    <% using (Html.BeginForm("Logon", "Account")) { %>
        <table>
            <tr><td><label for="username" style="width:10em">Matricule :</label></td><td><%= Html.TextBox("Matricule") %><%= Html.ValidationMessage("Matricule") %></td></tr>
            <tr><td><label for="password" style="width:10em">Mot de passe:</label></td><td><%= Html.Password("passWord") %><%= Html.ValidationMessage("passWord") %></td></tr>
            <tr><td></td><td><%= Html.CheckBox("rememberMe") %> <label for="rememberMe">Se souvenir de moi ?</label></td></tr>
            <tr><td></td><td><input type="submit" value="Se Connecter" /></td></tr>
        </table>
<% } %>

这是控制器:

public ActionResult LogOn()
        {

            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
            Justification = "Needs to take same parameter type as Controller.Redirect()")]
        public ActionResult LogOn(string Matricule, string passWord, bool rememberMe, string returnUrl)
        {

            if (!ValidateLogOn(Matricule, passWord))
            {
                return View();
            }

            FormsAuth.SignIn(Matricule, rememberMe);
            if (!String.IsNullOrEmpty(returnUrl))
            {
                return Redirect(returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }

感谢您的回答,
首先,我没有使用 WEB API。
我的应用程序是一个带有 C# 并使用 SQL SERVER 2005 数据库的 ASP MVC 3 应用程序。
其次,我将尝试解释更多:我创建了一个 Internet 应用程序(New Project-->ASP .NET MVC 3 WEB APPLICATION--> Internet Application)。
如您所知,当您创建 Internet 应用程序时,VS 为您创建了一种使用 Cookie 登录和注册的方式。
我使用 Entity Framework 4 和 Code First 创建了我的数据库(创建了许多模型,这些模型将在我的基础中生成为表)。
所以,我有一个表用户,其中包含一个 Nom(登录名)+ 密码。
我希望当我在我的 Web Inerface(文本框)中输入登录名和密码时,编辑器会验证它们在用户表中是否符合(存在)。

这是我的模型用户:

{
    public class User
    {
        [Required]
        [Key]
        [Display(Name = "Matricule :")]
        public string Matricule { get; set; }

        [Required]
        [Display(Name = "Nom :")]
        public string Nom_User { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "Le {0} doit avoir au minimum {2} caractères.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Mot de passe :")]
        public string passWord { get; set; }



        [Required]
        [ForeignKey("Account")]
        [Display(Name = "Type :")]
        public string Type_User { get; set; }

        [Required]
        [ForeignKey("UF")]
        [Display(Name = "ID UF :")]
        public string ID_UF { get; set; }

        public virtual Account Account { get; set; }
        public virtual UF UF { get; set; }

        public virtual ICollection<User> Users { get; set; }
    }

这是上下文文件:

namespace MvcApplication2.Models
{
    public class GammeContext : DbContext
    {
        public GammeContext()
        {

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<GammeContext>());

        }


        public DbSet<Account> Accounts { get; set; }
        public DbSet<Ns_AFaire> Ns_AFaires { get; set; }
        public DbSet<Famille> Familles { get; set; }
        public DbSet<Fonction> Fonctions { get; set; }
        public DbSet<Fonction_Poste> Fonction_Postes { get; set; }
        public DbSet<Gamme> Gammes { get; set; }
        public DbSet<Historique> Historiques { get; set; }
        public DbSet<Ligne> Lignes { get; set; }
        public DbSet<Phase> Phases { get; set; }
        public DbSet<Poste> Postes { get; set; }
        public DbSet<Produit> Produits { get; set; }
        public DbSet<Profile_Ga> Profil_Gas { get; set; }
        public DbSet<Sous_Famille> Sous_Familles { get; set; }
        public DbSet<UF> UFs { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Num_Serie> Num_Series { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();
        }


    }
}
4

0 回答 0