如果用户使用ASP.NET直接在浏览器中输入URL,如何重定向到登录页面 [英] how to redirect to login page if user directly entres URL in browser using ASP.NET

查看:253
本文介绍了如果用户使用ASP.NET直接在浏览器中输入URL,如何重定向到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究asp.net实体框架.我只想通过登录而不是直接输入页面的URL来访问页面.如果用户输入页面的URL并尝试访问它,则应将其重定向到登录页面. 我怎样才能做到这一点?用户应使用数据库中的用户名和密码登录. 我是ASP.NET的新手

I am working on asp.net entity framework. I want to access the pages only through login and not directly by entering the URL of the page. If user enters the URL of the page and tries to access it then he should be redirected to Login Page. How can I do that? User are supposed to login with username and password from DB. I am new to ASP.NET

推荐答案

正在寻找的功能可以通过将以下身份验证/授权部分添加到ASP.NET Web.config文件中来实现,如以下示例所示:

The functionality you are looking for can be achieved by adding the following authentication/authorization sections to the ASP.NET Web.config file like shown in the following example:

<system.web>
  <authentication mode="Forms">
    <forms name="SomeName" 
           loginUrl="Login.aspx" 
           protection="All" 
           path="/">
    </forms>
  </authentication>
  <authorization>
    <deny users="?" />
  </authorization>
</system.web>

它实质上拒绝未经身份验证的用户的所有访问:如果这种未经身份验证的用户尝试访问您网站上的任何页面,那么他/她将被重定向到Login.aspx页面(MSDN上的详细信息 https://msdn.microsoft.com/en-us/library/xdt4thhy.aspx ).

It essentially denies all access for unauthenticated Users: if such unauthenticated User tries to access any page at your website, then he/she will be redirected to the Login.aspx page ( details at MSDN https://msdn.microsoft.com/en-us/library/wce3kxhd.aspx, https://msdn.microsoft.com/en-us/library/xdt4thhy.aspx).

希望这会有所帮助.

这篇关于如果用户使用ASP.NET直接在浏览器中输入URL,如何重定向到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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