1
私は私のプロジェクトを実行すると、それは私がユーザ名とパスワードを入力すると エラーmvcを使用してログインせずにホームページが開かれましたか?私はセッションをログアウトし、クリアしたら
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
}
}
細かい作業ログインページに行くには、適切
//[Authorize]
//[InitializeSimpleMembership]
public class AccountController : Controller
{
//
// GET: /Account/
public ActionResult Index()
{
return View();
}
#region Login
[HttpGet]
[AllowAnonymous]
public ActionResult Login()
{
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(Login login)
{
if (ModelState.IsValid)
{
bool success = WebSecurity.Login(login.UserName, login.Password, false);
var UserID = GetUserID_By_UserName(login.UserName);
if (success == true)
{
Session["Name"] = login.UserName;
Session["UserID"] = UserID;
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("Error", "Please enter valid Username and Password");
return View(login);
}
}
return View(login);
}
#endregion
}
ログインし、 URLバーlocalhost:51426/Home/index
をホームページに入力すると、ホームページがloginなしで直接開かれました。ホームページはログインプロセスなしで開かないでください。
は、カスタム、それは – Saineshwar
承認フィルターに内蔵され使用してuのですが正しいです、それは私のために感謝 –
@Saineshwarフィルタ – Saineshwar