網絡mvc 3應用程序。.net mvc表單登錄網址重定向
我遇到了登錄表單的問題。
當我嘗試用我的管理員用戶登錄時,第一次沒有問題日誌,但如果我嘗試登錄任何其他問題,我必須登錄第二個登錄頁面。
第一種形式UR是這樣的:
與除了我的數據庫管理員用戶的任何其他用途我要嘗試一次,然後得到這個網址
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("/");
}
//}
}
}
}
這是它的工作方式:我有一個用戶,並通過我用帶我到/ ursmgmt頁。這個頁面是我的超級管理頁面。我在這裏創建公司。當我創建一家新公司時,我爲該公司創建了一個管理員。那麼公司將使用該登錄信息並登錄到其應用程序中,並可在其「用戶管理頁面」中設置額外的用戶。 – GTITC 2012-04-13 06:38:33
我作爲超級管理員創建的用戶以及公司爲其公司創建的任何其他用戶都具有用戶類型= 0。我創建的第一個用戶/公司管理員沒有任何權限。公司管理員在其用戶管理頁面中設置特權。所以這樣工作,只是爲了確保我很清楚:1)我使用用戶「admin」密碼登錄:「admin」,這會將我帶到超級管理公司創建頁面 – GTITC 2012-04-13 06:41:29
2)我創建一個名爲A1Company的新公司並設置該公司的管理員用戶名爲A1CompanyAdmin。 3)A1CompanyAdmin登錄到應用程序並進入用戶管理頁面,然後創建一個新用戶「A1CompanySalesUser」,然後賦予權限(勾選用戶可以訪問的5個頁面中的哪些頁面,所以只需點擊一個或所有頁面。 A1CompanySalesUser和A1CompanyAdmin都有用戶類型= 0可能是用戶類型或特權的問題 – GTITC 2012-04-13 06:41:43