简体   繁体   English

如果未经过身份验证,则将用户重定向到登录页面

[英]Redirecting user to login page if not authenticated

I am using the simple authentication thing.,,.. 我正在使用简单的身份验证。,, ..

Using this in config file.... 在配置文件中使用它....

<authentication mode="Forms">
   <forms name=".COOKIE" loginUrl="login.aspx" protection="All" path="/" timeout="480"/>
  </authentication>
  <authorization>
   <deny users="?"/>
   <allow users="*"/>
  </authorization>

The user who is not logged in should be sent back to login.aspx. 未登录的用户应该发送回login.aspx。 BUT currently it is not happening. 但目前还没有发生。 User is able to go to any page. 用户可以转到任何页面。 While it is working well in my local but not working on server. 虽然它在我的本地运行良好,但没有在服务器上工作。 What is the thing which I am missing... 我错过了什么......

Still seeking for the answer...... 还在寻找答案......

Couple of things to try: 有几件事要尝试:

  • remove <allow users="*"/> 删除<allow users="*"/>
  • close the browser, reopen it, clear all cookies, close the browser, reopen and go to site 关闭浏览器,重新打开它,清除所有cookie,关闭浏览器,重新打开并转到站点
  • check code in the login page to make sure it's not automatically authenticating the user 检查登录页面中的代码以确保它不会自动验证用户身份
  • try changing the cookie name...maybe it's being shared somehow? 尝试更改cookie名称...也许是以某种方式共享?

Seems like the config is all right. 似乎配置是可以的。 You might check if the machine.config or the IIS ASP.NET settings are overriding the Web.config you're using. 您可以检查machine.config或IIS ASP.NET设置是否覆盖了您正在使用的Web.config。

Make sure the FormsAuthentication module is added to the httpMdules collection. 确保将FormsAuthentication模块添加到httpMdules集合中。 You might try to add it your self in your web.config , in case it has been removed from machine.config . 您可以尝试在web.config添加它自己,以防它从machine.config删除。 This module is what handles the redirect to what you have specified under authentication/forms 此模块处理重定向到您在authentication/forms下指定的内容

I would deny unauthenticated users by default, only make exceptions for the login page and other resources needed. 我默认拒绝未经身份验证的用户,只为登录页面和所需的其他资源设置例外。

Example: 例:

    <authorization>
        <deny users="?"/>
    </authorization>

... ...

<location path="Login.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果用户未经过身份验证,请转到登录页面 - If user is not authenticated go to login page 用户单击按钮时重定向到登录页面 - Redirecting to login page when user clicks a button 在FormsAuthentication对用户进行身份验证之后,撤消身份验证并重定向到登录页面 - Revoking authentication and redirect to login page after FormsAuthentication have authenticated the user 表单身份验证后,MVC登录操作未重定向 - MVC login action not redirecting after form authenticated FormsAuthentication重定向到登录页面 - FormsAuthentication redirecting to login page 授权回调端点不断重定向到用户交互登录页面 IdentityServer - Authorize callback endpoint keeps redirecting to the user interaction login page IdentityServer 登录后重定向到登录页面 - Redirecting to Login page after Login 为什么未通过身份验证的用户不能通过Membership API自动重定向到“登录”页面? - Why isn't the un-authenticated user automatically redirected to the Login page with Membership API? 登录后重定向到特定页面 - Redirecting to specific page after Login 将匿名用户或错误的用户类型重定向到 ASP.net MVC 3 中特定控制器内的登录页面 - Redirecting Anonymous User or wrong user type to login page within a specific controller in ASP.net MVC 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM