MVC:重定向到登录屏幕 [英] MVC: Redirecting to login screen

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

问题描述

我将接管现有的ASP.NET MVC 5项目,以尝试了解MVC框架.我注意到,当用户未登录时,他尝试访问某些网页,那么它将自动将其重定向到登录屏幕.我相信这与Web.config文件中的以下内容有关:

I am taking over an existing ASP.NET MVC 5 project in order to try to understand the MVC framework. I have noticed that when a user is not logged in, and he attempts to go to some of the webpages, then it automatically redirects him to the login screen. I believe that this has something to do with the following in the Web.config file:

<authentication mode="Forms">
    <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

但是,即使用户未登录,某些网页仍允许访问它们(并且如上所述不进行重定向).

However, some webpages allow access to them (and are not redirected as above) even when the user is not logged in.

所以我的问题是:在哪里配置哪些网页将自动重定向到登录屏幕,以及哪些网页无需身份验证即可访问?

So my question is: Where do I configure which web pages will be automatically redirected to the login screen, and which web pages can be accessed without authentication?

推荐答案

文章 说明了如何使用表单身份验证进行此操作.简短的配置片段如下所示.授予default1.aspx访问权限的地方.

This article explains how to do this with forms authentication. A short snippet of the configuration looks like below. Where default1.aspx is given access to.

<configuration>
   <system.web>
      <authentication mode="Forms">
         <forms loginUrl="~/Account/Login" timeout="2880" />
      </authentication>
      <!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
      <authorization>
        <deny users="?" /> 
      </authorization>
   </system.web>
   <!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
   <location path="default1.aspx">
      <system.web>
         <authorization>
            <allow users ="*" />
         </authorization>
      </system.web>
   </location>
</configuration>

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

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