ASP.NET按页面授权(ASP.NET authorize by page)

编程入门 行业动态 更新时间:2024-10-26 00:29:58
ASP.NET按页面授权(ASP.NET authorize by page)

我在web.config文件中有这些设置。 只有两个授权标签。 一个是拒绝匿名用户而另一个是注册页面,所以任何人都可以访问它。 我怎样才能做到这一点?

<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>

单击“注册”按钮时,上面的这些设置会给我以下错误。

访问被拒绝。

描述:访问提供此请求所需的资源时发生错误。 可能未配置服务器以访问请求的URL。

错误消息401.2。:未授权:由于服务器配置登录失败。 验证您是否有权根据您提供的凭据和Web服务器上启用的身份验证方法查看此目录或页面。 请与Web服务器的管理员联系以获取其他帮助。

登录页面可访问。 我在web.config中有一个用户来测试,它工作正常。 我可以登录并访问所有页面。 但是如何才能使注册页面可访问?

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?

最满意答案

你是对的@Seyed Morteza Mousavi,我的问题在注册链接!

我创建网站时默认看起来像这样。

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

我把它改成了这个。

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

它现在有效。 我不知道为什么默认一个不起作用但我不在乎了。 此外,登录链接旁边的Site.Master中的注册链接不起作用。 它会一直重定向到登录页面! 再也不清楚为什么。 但现在这是可以的。

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.

更多推荐

访问,access,page,Web,电脑培训,计算机培训,IT培训"/> <meta name="descriptio

本文发布于:2023-04-29 11:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   NET   ASP   authorize   page

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!