我在使用身份验证我正在处理的项目中的用户时遇到了问题。
我不明白为什么,但是在离开public void Configuration(IAppBuilder app)
之后,一个参数returnUrl被添加到我的uri并使它崩溃,因为uri太长了。
这是uri返回的
http://localhost:51092/Login/Index?ReturnUrl=%2FLogin%2FIndex%3FReturnUrl%3D%252FLogin%252FIndex%253FReturnUrl%253D%25252FLogin%25252FIndex%25253FReturnUrl%25253D%2525252FLogin%2525252FIndex%2525253FReturnUrl%2525253D%252525252FLogin%252525252FIndex%252525253FReturnUrl%252525253D%25252525252FLogin%25252525252FIndex%25252525253FReturnUrl%25252525253D%2525252525252FLogin%2525252525252FIndex%2525252525253FReturnUrl%2525252525253D%252525252525252FLogin%252525252525252FIndex%252525252525253FReturnUrl%252525252525253D%25252525252525252FLogin%25252525252525252FIndex%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252FLogin%2525252525252525252FIndex%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252FLogin%252525252525252525252FIndex%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252FLogin%25252525252525252525252FIndex%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252FLogin%2525252525252525252525252FIndex%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252FLogin%252525252525252525252525252FIndex%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252FLogin%25252525252525252525252525252FIndex%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252FLogin%2525252525252525252525252525252FIndex%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252FLogin%252525252525252525252525252525252FIndex%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252FLogin%25252525252525252525252525252525252FIndex%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252FLogin%2525252525252525252525252525252525252FIndex%2525252525252525252525252525252525253FReturnUrl%2525252525252525252525252525252525253D%252525252525252525252525252525252525252FHome%252525252525252525252525252525252525252FIndex
另外显示错误列表并且我的控制器的物理路径很奇怪,因为Index是应该调用的函数,但它似乎就像一个文件
C:\Projects\vs\project\project\Login\Index
这是我的cConfiguration函数
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieSecure = CookieSecureOption.Always,
LoginPath = new PathString("/Login/Index"),
Provider = new CookieAuthenticationProvider
{
}
});
如果有人看错了
编辑:这是登录控制器中的函数索引
// GET: Login
[HttpGet]
public ActionResult Index()
{
return View();
}
using Gesmar_intra.Models;
using Gesmar_intra.Models.Entite;
using Microsoft.AspNet.Identity.Owin;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
namespace Gesmar_intra.Controllers
{
public class LoginController : Controller
{
protected Gesmar db = new Gesmar();
private ApplicationSignInManager _signInManager;
public LoginController()
{
}
public LoginController(ApplicationSignInManager signInManager)
{
SignInManager = signInManager;
}
public ApplicationSignInManager SignInManager
{
get
{
return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
}
private set
{
_signInManager = value;
}
}
// GET: Login
[HttpGet]
public ActionResult Index(string returnUrl)
{
return View();
}
[HttpPost]
public ActionResult Index(FormCollection form)
{
var username = Request.Form["username"];
var password = Request.Form["password"];
var passHash = Utilisateur.GenerateSHA256String(password);
if (Utilisateur.CheckAccount(username, "APRRR", password))
{
password = "";
}
var result = SignInManager.PasswordSignIn(username, password, false, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToAction("Test", "Login");
case SignInStatus.LockedOut:
return View();
case SignInStatus.RequiresVerification:
return View();
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Tentative de connexion non valide.");
return View();
}
}
[Authorize]
public ActionResult Test()
{
return View();
}
}
}