net mvc 3申请。
我的登录表单存在问题。
当我尝试使用我的管理员用户登录时,第一次没有问题日志,但如果我尝试登录任何其他问题,我必须登录第二个登录页面。
首先形成你的是:
除了我的数据库管理员用户以外的任何其他用途我必须尝试一次然后获取此URL
http://HOST.com/Login/Login?ReturnUrl=%2f
重定向并重试,然后正确登录。每次都会发生。
这是我的web.config
中表单部分的表单代码<authentication mode="Forms">
<forms loginUrl="Login/Login" timeout="200000" slidingExpiration="true">
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
感谢您提出任何建议
登录表单文件:
using System;
using System.Web.Mvc;
using System.Web.Security;
using SAMPLE.Models;
using SAMPLE.Helpers;
using System.Web;
using System.Linq;
namespace SAMPLE.Controllers
{
public class LoginController : Controller
{
public ActionResult Login(string username, string password, string returnUrl)
{
if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password))
{
if (UserAccount.IsValid(username, password))
RedirectFromLoginPage(username, returnUrl);
else
ViewData["LoginMessage"] = "Incorrect username or password.";
}
return View();
}
public ActionResult Logout()
{
FormsAuthentication.SignOut();
return RedirectToAction("Login", "Login");
}
private void RedirectFromLoginPage(string username, string returnUrl)
{
FormsAuthentication.SetAuthCookie(username, false);
var userType = 0;
var user = UserAccount.SingleOrDefault(x => x.Username == username.ToLower());
if(user!=null)
userType = user.UserType;
if (userType == 2)
{
Response.Redirect("/Usrmgmt");
}
else
{
var privileges = SAMPLE.Helpers.SAMPLEContext.Privileges;
if ((privileges & PrivilegeConstants.Home) == PrivilegeConstants.Home)
Response.Redirect("/");
else if ((privileges & PrivilegeConstants.Budgets) == PrivilegeConstants.Budgets)
Response.Redirect("/Budget");
else if ((privileges & PrivilegeConstants.Estimates) == PrivilegeConstants.Estimates)
Response.Redirect("/Estimate");
else if ((privileges & PrivilegeConstants.EstimageCatalogue) == PrivilegeConstants.EstimageCatalogue)
Response.Redirect("/Labour");
else if ((privileges & PrivilegeConstants.CRM) == PrivilegeConstants.CRM)
Response.Redirect("/CRM");
else if ((privileges & PrivilegeConstants.JobStatus) == PrivilegeConstants.JobStatus)
Response.Redirect("/JobStatus");
else if ((privileges & PrivilegeConstants.UserManage) == PrivilegeConstants.UserManage)
Response.Redirect("/Administration");
else
Response.Redirect("/");
}
//}
}
}
}
答案 0 :(得分:1)
请将您的web.config更改为:
<authentication mode="Forms">
<forms loginUrl="~/Login/Login" timeout="2880" protection="All"/>
</authentication>
删除下面的代码,然后重试:
<authorization>
<deny users="?" />
</authorization>