ASP.NET MVC4重定向到登录页面 [英] ASP.NET MVC4 Redirect to login page

查看:118
本文介绍了ASP.NET MVC4重定向到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用ASP.NET MVC 4和C#的Web应用程序。

I'm creating a web application using ASP.NET MVC 4 and C#.

我希望所有用户使用应用程序之前登录。

I want all users to be logged in before using application.

我使用ASP.NET成员具有自定义数据库。

I'm using ASP.NET Membership with a custom database.

一种方法是检查 Membership.GetUser()为空或不是在每一个功能。

One method is check if Membership.GetUser() is null or not in every function.

但是,是不是有不是在每个功能检查用户登录状态的更简单的方法吗(在web.config中,Global.asax的,也许等检查......?)

But isn't there any easier way than checking user login state in every function? (maybe checking in web.config, global.asax, etc...??)

推荐答案

当然,装点您的行为或全班<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx\"><$c$c>[Authorize]它将要求该用户在第一次登录

Sure, decorate your actions or the whole class with [Authorize] and it will require that the user is logged in first.

这篇关于ASP.NET MVC4重定向到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆