<authentication mode="Forms"> <forms loginUrl="~/Authentication/Login"></forms>
来源:互联网 发布:机械加工编程软件 编辑:程序博客网 时间:2024/04/28 09:58
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Authentication/Login"></forms>
</authentication>
namespace MvcAppLesson4.Controllers
{
public class HomeController : Controller
{
[Authorize]
public ActionResult Index()
{
SalesERPDAL salesDal = new SalesERPDAL();
List<Employee> employees = salesDal.Employees.ToList();
return View("EmployeeListView", employees);
}
[Authorize]
public ActionResult EmployeeListView()
{
SalesERPDAL salesDal = new SalesERPDAL();
List<Employee> employees = salesDal.Employees.ToList();
return View("EmployeeListView", employees);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcAppLesson4.Models;
using System.Web.Security;
namespace MvcAppLesson4.Controllers
{
public class AuthenticationController : Controller
{
//
// GET: /Authentication/
public ActionResult Index()
{
return View();
}
//Authentication/Login
// GET: Authentication
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult DoLogin(UserDetails u)
{
EmployeeBusinessLayer bal = new EmployeeBusinessLayer();
if (bal.IsValidUser(u))
{
FormsAuthentication.SetAuthCookie(u.UserName, false);
return RedirectToAction("Index", "HOME");
}
else
{
ModelState.AddModelError("CredentialError", "Invalid Username or Password");
return View("Login");
}
}
}
}
@model MvcAppLesson4.Models.UserDetails
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Login</title>
</head>
<body>
<div>
@Html.ValidationMessage("CredentialError", new {style="color:red;" })
@using (Html.BeginForm("DoLogin", "Authentication", FormMethod.Post))
{
@Html.LabelFor(c=>c.UserName)
@Html.TextBoxFor(x=>x.UserName)
<br />
@Html.LabelFor(c => c.Password)
@Html.PasswordFor(x => x.Password)
<br />
<input type="submit" name="BtnSubmit" value="Login" />
}
</div>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcAppLesson4.Models
{
public class EmployeeBusinessLayer
{
public bool IsValidUser(UserDetails u)
{
if (u.UserName == "Admin" && u.Password == "Admin")
{
return true;
}
else
{
return false;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcAppLesson4.Models
{
public class UserDetails
{
public string UserName { get; set; }
public string Password { get; set; }
}
}
- <authentication mode="Forms"> <forms loginUrl="~/Authentication/Login"></forms>
- <authentication mode="Forms"> 发布错误
- Asp.net authentication mode="Forms"
- Web应用程序中的服务器错误 (<authentication mode="Forms">)
- windows + forms 混合 Authentication
- Forms Authentication 概述
- ASP.NET forms authentication
- Forms Authentication MVC 4
- asp.net Forms Authentication
- 关于IIS 中 “/”应用程序中的服务器错误。<authentication mode="Forms"/> 错误的处理
- ASP.NET&C#学习笔录4(<authentication mode="Windows|Forms|Passport|None"> )
- 没有生成forms authentication cookie
- <authentication+mode="Forms">+是应用级别的...在子目录下用+<authorization>节来控制访问的解决方法
- Forms authentication without a (visible) form
- [ZT]Generating Forms Authentication Compatible Passwords (SHA1)
- [转贴]Forms authentication and role-based security
- Role-based Security with Forms Authentication
- Role-based Security with Forms Authentication
- 关于ie7、8 DOM上属性的获取
- select 用法
- Android之Button点击样式类库ActionProcessButton的使用
- 什么是IaaS, PaaS和SaaS及其区别
- oracle11g的完全删除
- <authentication mode="Forms"> <forms loginUrl="~/Authentication/Login"></forms>
- jQuery适合移动设备触摸屏的响应式幻灯片插件
- Linux系统搭建Red5服务器
- 咯lol
- 原创——电商网站(部分)
- hadoop virtual memory limits
- 《核心动画——关键帧动画》
- 151. Reverse Words in a String
- Zobrist 哈希