0

net mvc 3 アプリケーション。

ログインフォームに問題があります。

管理者ユーザーでログインしようとすると、最初はログに問題はありませんが、他の問題でログインしようとすると、2 番目のログイン ページからログインする必要があります。

最初のフォームウルはこれです:

http://HOST.com/Login/Login

私のdb管理者ユーザー以外の他の用途では、一度試してからこの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("/");
            }
            //}
        }
    }
}
4

1 に答える 1

1

web.configを次のように変更してください。

<authentication mode="Forms">
   <forms loginUrl="~/Login/Login" timeout="2880" protection="All"/>
</authentication>

以下のコードを削除して、再試行してください。

<authorization>
  <deny users="?" />
</authorization>
于 2012-04-10T07:45:08.323 に答える