我們有一個古老的經典asp應用程序,用於管理和啓動我們的其他web應用程序。放置此認證邏輯的適當位置在哪裏?
它啓動的應用程序的方法是如下:
<form name="frmMain" action="http://xxxx/mvc3app/Index" target=_self method=post>
<script language="javascript">
frmMain.submit();
</script>
用戶登錄名和密碼被通過作爲請求的一部分傳遞。
驗證用戶在ASP.NET應用程序我把下面的authenticateUser功能:
public bool AuthenticateUser()
{
var userName = Context.Request["txtName"];
var password = Context.Request["txtPassword"];
if (Membership.ValidateUser(userName, password))
{
FormsAuthentication.SetAuthCookie(userName, true);
}
}
我認爲正確的地方打電話的authenticateUser將在Global.asax中Session_Start()
方法,但它不在提交「frmMain」時似乎並沒有提到這種方法。它似乎間歇性地工作 - 如果我完全關閉IE,請再試一次,然後手動輸入URL。
void Session_Start(object sender, EventArgs e)
{
Log("In Session Start");
AthenticateUser();
}
哪裏將是正確的地方,在我的ASP.NET應用程序來驗證用戶的身份?
這是一個屏幕開發工具的形式認證失敗 - Session_Start()不被調用。
編輯
看起來這是行不通的,因爲IsAuthenticated屬性只在其上造成AUTH失敗的索引操作的後續請求設置。
我現在會測試這個,但看到Who sets the IsAuthenticated property of the HttpContext.User.Identity
解決方案:
第一個錯誤調用SetAuthCookie這是導致指數以失敗驗證後沒有重定向。
我也意識到,沒有必要把這個在Global.asax中,但我寧願重定向到一個登錄行動,而不是直接到索引操作:
public ActionResult LogOn()
{
var userName = Context.Request["txtName"];
var password = Context.Request["txtPassword"];
if (Membership.ValidateUser(userName, password))
{
FormsAuthentication.SetAuthCookie(userName, false);
return RedirectToAction("Index", "Index");
}
else
{
return RedirectToAction("IncorrectLogin", "Index");
}
}
上的登錄操作.... – devundef 2012-07-24 09:13:41
'Session_Start'被稱爲當用戶第一次來到你網頁。這是新會議的開始。考慮瀏覽webform應用程序的頁面和應用程序生命週期。 =) – 2012-07-24 09:13:43
這看起來不像傳統的ASP給我。你的意思是Asp.net的網頁表單? – podiluska 2012-07-24 10:16:07