Я сталкиваюсь с проблемой использования идентификатора для аутентификации пользователя в проекте, над которым я работаю.
Я понятия не имею, почему, но после выхода public void Configuration(IAppBuilder app)
параметр returnUrl добавляется в мой 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
{
}
});
Если кто-то видит что-то не так
Редактировать: вот моя функция Index в контроллере входа
// 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();
}
}
}