62,041
社区成员
发帖
与我相关
我的任务
分享
[HttpPost]
public ActionResult Login(string txtaccount, string txtpwd)
{
var kid = HttpContext.User.Identity;
DalAllUsers dalallusers = new DalAllUsers();
FormsAuthentication.SetAuthCookie(txtaccount, dalallusers.checklog(txtaccount, txtpwd) == "成功");
bool x = User.Identity.IsAuthenticated;
//HttpContext.User.Identity.Name = txtaccount.ToString();
//HttpContext.Session["theid"] = txtaccount.ToString();
//Session["txtaccount"] = txtaccount.ToString();
Session["userid"] = txtaccount.ToString();
string checkresult = dalallusers.checklog(txtaccount, txtpwd);
return RedirectToAction("MyIndex", "Mymain");
//return Json(checkresult);
}
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Login/Login" timeout="2880" />
</authentication>
<identity impersonate="true"/>
<compilation debug="true" targetFramework="4.0" />
public class MyCommonAuthorizeAttribute:AuthorizeAttribute
{
DalAllUsers dalallusers = new DalAllUsers();
private bool isAllowed = true;
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null)
{
throw new ArgumentNullException("HttpContext");
}
if (!httpContext.User.Identity.IsAuthenticated)//判断用户是否通过验证 验证登陆
{
return false;
}