Log in

View Full Version : MVC login reset help...



Autoservice
04-03-2012, 12:33 AM
Hi guys,

I made an mvc3 login page and when I login I press the back button on my browser which brings me back to the login page, but when i press forward again it logs me in again, i want to prevent it from keeping me logged in. I hope you got that :)


Autoservice.

traq
04-03-2012, 12:55 AM
when your login page receives a login attempt, it needs to check if the user is already logged in before doing anything else.

...If I understood you problem correctly. If not,
Your question is unclear.
Please provide more information, and be as specific as possible.
What do you want to accomplish? What have you already tried? What problems did you encounter?
Also, please be sure that you have included all relevant code and/or a link to the page in question.

Autoservice
04-03-2012, 01:07 PM
"when your login page receives a login attempt, it needs to check if the user is already logged in before doing anything else." Yes this is what i want to accomplish, sorry for the bad explanation to my question, I was very tired last night ^^ .

traq
04-03-2012, 02:48 PM
I've never seen your code, so I don't have any more specific advice

( hint, hint ... )

Autoservice
04-04-2012, 12:05 AM
I've never seen your code, so I don't have any more specific advice

( hint, hint ... )

Sorry, i have much work to do (projects)

So the code is below ;)


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CarReviews.Models;

namespace CarReviews.Controllers

{
[Authorize]
public class CarController : Controller
{
private RidesEntities db = new RidesEntities();

//
// GET: /Default1/
[Authorize(Roles = "Admin")]
public ViewResult Index()
{
var cars = db.Cars.Include(c => c.Pricing);
return View(cars.ToList());
}

//
// GET: /Default1/Details/5

public ViewResult Details(int id)
{
Car car = db.Cars.Find(id);
return View(car);
}

//
// GET: /Default1/Create
// [Authorize(Users="Bob")]
[Authorize(Roles = "admin")]
[Authorize(Roles = "user")]

public ActionResult Create()
{
ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group");
return View();
}

//
// POST: /Default1/Create

[HttpPost]
public ActionResult Create(Car car)
{
if (ModelState.IsValid)
{
db.Cars.Add(car);
db.SaveChanges();
return RedirectToAction("Index");
}

ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group", car.price_id);
return View(car);
}

//
// GET: /Default1/Edit/5

public ActionResult Edit(int id)
{
Car car = db.Cars.Find(id);
ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group", car.price_id);
return View(car);
}

//
// POST: /Default1/Edit/5

[HttpPost]
public ActionResult Edit(Car car)
{
if (ModelState.IsValid)
{
db.Entry(car).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group", car.price_id);
return View(car);
}

//
// GET: /Default1/Delete/5

public ActionResult Delete(int id)
{
Car car = db.Cars.Find(id);
return View(car);
}

//
// POST: /Default1/Delete/5

[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Car car = db.Cars.Find(id);
db.Cars.Remove(car);
db.SaveChanges();
return RedirectToAction("Index");
}

protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}

hamada76
04-24-2012, 06:05 AM
Kill all the sessions on the login page before the login script.