我在Visual Studio 2013中创建了库存ASP.NET Web应用程序。在自定义母版页后,我想添加从任何地方登录的功能,而不是将用户定向到/Account/Login.aspx。所以我在母版页的标题中添加了一个下拉表单。 我将相关代码从login.aspx.cs复制到Site.Master.cs,
#ifndef TESTDLL_LOADCONFIG_H
#define TESTDLL_LOADCONFIG_H __declspec(dllexport)
#else
#define TESTDLL_LOADCONFIG_H __declspec(dllimport)
#endif
所有声明
protected void LogIn(object sender, EventArgs e)
{
if (IsValid)
{
// Validate the user password
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
// This doen't count login failures towards account lockout
// To enable password failures to trigger lockout, change to shouldLockout: true
var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
//string youruser = User.Identity.GetUserId().ToString();
//Session["YourUser"] = youruser;
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
break;
case SignInStatus.LockedOut:
Response.Redirect("/Account/Lockout");
break;
case SignInStatus.RequiresVerification:
Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
Request.QueryString["ReturnUrl"],
RememberMe.Checked),
true);
break;
case SignInStatus.Failure:
default:
FailureText.Text = "Invalid login attempt";
ErrorMessage.Visible = true;
break;
}
}
}
和这一行
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using OnStageTonightWebForms.Models;
然而,当我运行应用程序时,它会抛出错误&#34;名称&#39; IsValid&#39;在当前背景下不存在&#34;在代码中,IsValid下面有一条红色的摇摆线。 login.aspx.cs中没有红线。
这两个文件的代码是相同的,那么为什么一个工作而另一个工作呢?