简体   繁体   English

Register.aspx将匿名用户重定向到“登录”页面

[英]Register.aspx redirects Anonymous users to Login page

I'm using asp.net Identity 2, In web.config under Account folder I have the following 我正在使用asp.net Identity 2,在web.config中的Account文件夹下,我有以下内容

<location path="Register.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>
<system.web>
   <authorization>
       <deny users="?" />
   </authorization>
</system.web>

The problem is that when I try to access the register.aspx it redirects me to the login page. 问题是,当我尝试访问register.aspx时,它会将我重定向到登录页面。 I need unauthorized users to be able to access the registration page 我需要未经授权的用户才能访问注册页面

You could use the allowOverride on a location to set the global deny authorization: 您可以在某个位置上使用allowOverride来设置全局拒绝授权:

<location path="Register.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>
<location allowOverride="true">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>

This will handle your redirect issue on Register, but will leave you having to make additional exceptions for your assets, such as images, scripts, and styles. 这将解决您在Register上的重定向问题,但将使您不得不对资产进行其他例外处理,例如图像,脚本和样式。

As an alternative approach, I find it easier trying to avoid having to manage massive lists of these location tags by leaving authorization to be done by directory. 作为一种替代方法,我发现通过保留目录授权来避免必须管理这些位置标签的大量列表会更容易。 Maybe it makes sense to leave the shared assets and non-secured pages off the root level like this and put your secured pages in different subfolders you secure through web.configs inside those folders. 像这样将共享资产和非安全页面保留在根级别之下,或者将安全页面放在通过这些文件夹内的web.configs保护的不同子文件夹中,也许是有道理的。

Project
/images/...
/styles/...
/secured/account.aspx
/secured/web.config (this is where you'd have your `deny` authorization)
/Register.aspx
/web.config (use allow all users at this level)

Now you can easily manage which users access which files, and it's much cleaner. 现在,您可以轻松地管理哪些用户访问哪些文件,并且更加干净。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM