获取 Asp.Net 表单身份验证以使用 403 自定义错误页面而不是登录页面

发布于 2024-10-03 14:50:58 字数 716 浏览 0 评论 0原文

我有一个使用表单身份验证的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文