我有一个网站,如果他们没有登录,我希望用户被重定向到"登录"页面.用户可以尝试通过发布网址来访问网页.我想在C#MVC 4.5中做到这一点
除非已登录,否则我不希望"[授权]"操作可用.它是查看索引页面的索引操作.
//Login Controller
[AllowAnonymous]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(FormCollection frm)
{
....//other code
}
[Authorize]
public ActionResult Index()
{
List<DTO> obj = objConfigurator.GetDataList();
return View(obj);
}
public ActionResult Edit(int Id)
{
DTO obj = objC.GetListById(Id);
return View(obj);
}
Run Code Online (Sandbox Code Playgroud)