小编Pra*_*nav的帖子

如果用户尝试通过URL访问其他网站页面,如何在C#MVC 4.5中重定向用户(无论是否登录到登录页面)

我有一个网站,如果他们没有登录,我希望用户被重定向到"登录"页面.用户可以尝试通过发布网址来访问网页.我想在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)

session c#-4.0 asp.net-mvc-4

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-mvc-4 ×1

c#-4.0 ×1

session ×1