ASP.NET authorize by page

I have these settings in my web.config file. Only two authorization tags. One to deny anonymous users and another for the register page so anyone can access it. How can I achieve that?

<configuration>
  <system.web>
    <authorization>
      <deny users="?"/>
      <!--Deny access to unauthorized users-->
    </authorization>
  ...
  </system.web>
  <location path="Account/Register.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
</configuration>

These settings above give me the following error when I click on the Register button.

Access is denied.

Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.

The login page is accessible. I have a user in the web.config to test and it works fine. I can login and access all pages. But how can I make register page accessible?


You are right @Seyed Morteza Mousavi, my problem was in the register link!

The default looked like this when I created the site.

 <asp:HyperLink runat="server" ID="RegisterHyperLink" ViewStateMode="Disabled">Register</asp:HyperLink> if you don't have an account.

I changed it to be this.

<asp:LinkButton runat="server" ID="lnkRegister" PostBackUrl="~/Account/Register.aspx" CausesValidation="false">Register</asp:LinkButton> if you don't have an account.

It works now. I don't know why default one doesn't work but I don't care anymore. Also, the Register link in the Site.Master next to Login link does not work. It keeps redirecting to Login page! Again not sure why. But this is OK for now.

链接地址: http://www.djcxy.com/p/55858.html

上一篇: 来自Facebook / home的音乐元失踪

下一篇: ASP.NET按页面授权