0
我想要做mvc框架的身份驗證,但如果我登錄並複製網址並從頁面註銷並在其他瀏覽器或選項卡中打開它應該去登錄頁面,但其重定向到哪個頁面需要先進行身份驗證意味着直接進入登錄頁面而無需身份驗證 。任何幫助都將被優先處理。窗體身份驗證與mvc框架
這裏是我的web配置設置:
<!--Using forms authentication-->
<location path="Content">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<!-- allow any user to see the login controller -->
<location path="~/Developer/Index">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="~/Developer/Index" timeout="2880" />
</authentication>
And in my controller login Action method i used
[HttpPost]
public ActionResult LoginAPI(LoginAPIFormModel loginapp)
{
if (!ModelState.IsValidField("username") || !ModelState.IsValidField("pwd"))
{
if (!ModelState.IsValidField("username"))
{
ModelState.AddModelError("username", "Invalid Email");
}
else
{
ModelState.AddModelError("Incomplete", "Please fill out each field");
}
return View(loginapp);
}
try
{
var context = new ndCorp_SiteEntities();
var Hashpwd = CreateHash(loginapp.pwd);
var res = context.DevUserInfoes.Where(i => i.UserName == loginapp.username && i.USerPwd == Hashpwd).FirstOrDefault() ;
TempData["mode"] = "LoginAPI";
FormsAuthentication.SetAuthCookie(loginapp.username, false);
return RedirectToAction("SuccessView");
}
catch (Exception ex)
{
Console.Write(ex);
return View(loginapp);
}
}
下面是javascript代碼登錄後這實際上重定向到用戶PAG:
if (@Html.Raw(Json.Encode(TempData["mode"])) == "LoginAPI")
{
parent.closeFancybox();
//setTimeout(parent.closeFancybox(), 1000)
//window.top.closeFancybox();
var url = '@Html.Raw(Url.Action("ManageApps", "Developer", new { username [email protected](Json.Encode(TempData["uname"]))}))';
url = url.replace(/%22/g,'');
parent.location.href = url;
}
嘗試更具體一些,也許發佈一些代碼。你也可以描述你的意思是「不工作」,任何錯誤代碼或錯誤信息? –
我再次發佈我的查詢與更多的代碼...我沒有得到任何錯誤,但如果我複製URL後登錄該網址在任何瀏覽器或選項卡沒有身份驗證例如。如果我從我的應用程序logogg,但它的開放http:// localhost:54971/en-us/Developer/ManageApps?username = test,則此url不起作用 – user207888