0

I'm new to ASP.NET and not the most experienced of programmers.

I have recently been introduced to ASP.NET-MVC 3 for an application I'd like to build.

I have the basic functionality down but am not to familiar with the login.

The built-in login works for what I want (just something simple), but I want to ensure that a login must be used before any of the actual functionality appears.

What would be the best way of doing this?

Any help would be greatly appreciated.

4

1 回答 1

1

在您的控制器中,您应该使用 Authorize 属性,这会在执行修饰操作之前强制授权。

例如,在您的家庭控制器中添加以下[Authorize]内容

[Authorize]
public ViewResult Index()
{
    return View();
}

您还可以装饰整个控制器,这将强制所有方法在使用之前被授权,例如:

[Authorize]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}
于 2013-04-24T13:29:33.257 回答