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

查看:35
本文介绍了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 Membership 与自定义数据库一起使用.

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...??)

推荐答案

当然,用 [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天全站免登陆