获取 Asp.Net 表单身份验证以使用 403 自定义错误页面而不是登录页面
我有一个使用表单身份验证的 Asp.Net 站点,我还在 web.config 中配置了自定义错误。其中之一是 403(访问被拒绝)的特殊错误页面。我的问题是如何让表单身份验证更智能地工作?
我希望表单身份验证仅在用户未经身份验证时才将其发送到登录页面。如果是的话,我希望它遵循我在 web.config 中定义的自定义错误页面。这似乎是一个非常基本的事情,如何实现呢?
<authentication mode="Forms">
<forms name=".TTCookie" loginUrl="Login.aspx" slidingExpiration="true" timeout="43200" />
</authentication>
<customErrors mode="On">
<error statusCode="403" redirect="~/ErrorPages/403.aspx"/>
<error statusCode="404" redirect="~/ErrorPages/404.aspx"/>
<error statusCode="404" redirect="~/ErrorPages/500.aspx"/>
</customErrors>
我通过上述配置观察到的是,当我点击一个无法访问的页面时,即使我已经通过了身份验证,它也会将我踢回到login.aspx。
I've a got an Asp.Net site that is using Forms authentication, I've also got custom errors configured in the web.config. One of these is a special error page for 403's (access denied). My question is how do I get Forms authentication to work smarter?
I would like Forms authentication to send users to login page only if they are not authenticated. If they are I want it to defer to the custom error pages that i've defined in the web.config. This seems like something very basic, how can this be achieved?
<authentication mode="Forms">
<forms name=".TTCookie" loginUrl="Login.aspx" slidingExpiration="true" timeout="43200" />
</authentication>
<customErrors mode="On">
<error statusCode="403" redirect="~/ErrorPages/403.aspx"/>
<error statusCode="404" redirect="~/ErrorPages/404.aspx"/>
<error statusCode="404" redirect="~/ErrorPages/500.aspx"/>
</customErrors>
What i'm observing with the above configuration is that when I hit a page I don't have access to it kicks me back to login.aspx even though i'm already authenticated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论