我有一个使用表单身份验证的简单MVC项目。当用户单击登录按钮时,控制器中的代码部分被调用:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> OturumAc(LoginViewModel model, string returnUrl)
{
//OturumAcmaSonuc = ResultOfLogin, sonuc = result
OturumAcmaSonuc sonuc = null;
//Kullanici = User
Kullanici kullanicisi = null;
//Anasayfa = MainPage
AnasayfaViewModel anasayfaModel = null;
PersonelViewModel personelvm = null;
if (!ModelState.IsValid)
{
return View(model);
}
try
{
personelvm = new PersonelViewModel();
//AcOturum = Login
sonuc = this._personelik.AcOturum(model);
// OturumAcmaSonucu = CanSheLogin
if (sonuc.OturumAcmaSonucu)
{
FormsAuthentication.SetAuthCookie(sonuc.Kullanicisi.KullaniciAdi, false);
kullanicisi = sonuc.Kullanicisi;
//Depola = Store
this._cache.Depola(CacheDepolamaEnum.Kullanici, kullanicisi);
anasayfaModel = new AnasayfaViewModel(sonuc.Mesaj, kullanicisi);
//Depola = Store
this._cache.Depola(CacheDepolamaEnum.AnasayfaViewModel, anasayfaModel);
//Anasayfa = MainPage
return RedirectToAction("Anasayfa", "Account");
}
else
{
TempData["Hata"] = SistemMesajlar.BasarisizOturumAcma();
}
}
catch (Exception Hata)
{
this._hataik.YazHata(Hata);
}
return View(model);
}
此操作方法应是登录的最终方法。正如您所期望的那样,当登录结果为真时,执行期望分支到&#34; Anasayfa&#34; (MainPage)动作方法,但它分支到&#34;登录&#34;行动方法。这是错误。以下是Web层的web.config的内容:
<system.web>
<globalization uiCulture="tr-TR" culture="tr-TR" />
<compilation debug="true" targetFramework="4.5.2" />
<authentication mode="Forms">
<forms loginUrl="/Account/OturumAc" timeout="20" slidingExpiration="true" />
</authentication>
<customErrors defaultRedirect="/Error" mode="On">
</customErrors>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
当我写&#34;登录&#34;动作方法如下所述,它分支到Login.cshtml:
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
我试着找到两个解决方案:
1-)每当用户成功登录时,它应分支到&#34; Anasayfa&#34; (MainPage)动作方法。 1-)执行不得分支到&#34;登录&#34;动作方法,它应该分支出来&#34; OturumAc&#34;行动方法。
我怎样才能克服这些?提前谢谢。