登录问题在asp.net MVC 3中

时间:2012-04-30 16:26:32

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-2

我在我自己的网站上使用MVC音乐商店登录表单和控制器,但它不起作用..

我正在使用此命名空间:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyApp.Models;
using System.Web.Security;

和控制器中的代码:

[HttpPost]
        public ActionResult login(tblAdmin model,  string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.Username, model.Password))
                {

                    FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "news");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }
            return View(model);
        }

这是在我的剃刀页面中:

@model MyApp.Models.tblAdmin
@{
    ViewBag.Title = "login";
    Layout = "~/Views/admin/Views/Shared/_Layout.cshtml";
}

@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")

@using (Html.BeginForm()) {
    <div>
        <fieldset>
            <legend>Account Information</legend>

            <div class="editor-label">
                @Html.LabelFor(m => m.Username)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.Username)
                @Html.ValidationMessageFor(m => m.Username)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>

            <div class="editor-label">
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe)
            </div>

            <p>
                <input type="submit" value="Login" />
            </p>
        </fieldset>
    </div>
}

我没有为我的字段使用类,我使用数据库和ado.net实体数据模型..我将它连接到我的表(tbladmin)..问题是什么?

问题出在我的代码的这一部分:

if (Membership.ValidateUser(model.Username, model.Password)

它说我的用户名和密码无效..但我在我的表中添加了用户名和密码..

0 个答案:

没有答案