1

我正在使用位于http://haacked.com/archive/2011/10/04/prevent-forms-authentication-login-page-redirect-when-you-donrsquot-want.aspx的 SuppressFormsAuthenticationRedirectModule来防止重定向某些 HTTP 401状态并改为显示自定义页面。

但是,我将 Object Moved Here 作为输出。如何改为显示我的自定义页面?

页面如下

<%@ Page Title="Unauthorized" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="UnauthorizedError.aspx.vb" Inherits="WebFormsTemplate.UnauthorizedError" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <h2>Unauthorized</h2>
    You do not have permission to view this page.
</asp:Content>

背后的代码

Imports System.Net
Imports Appahoo.Web.WebForms

Public Class UnauthorizedError
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SuppressFormsAuthenticationRedirectModule.SuppressAuthenticationRedirect(Me.Context, False)
        Me.Response.StatusCode = HttpStatusCode.Unauthorized
    End Sub
End Class
4

1 回答 1

0

没有意识到 SuppressAuthenticationRedirect 已经将状态设置为 HttpStatusCode.Unauthorized。因此我应该删除 Me.Response.StatusCode = HttpStatusCode.Unauthorized 让页面呈现。

Imports System.Net
Imports Appahoo.Web.WebForms

Public Class UnauthorizedError
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SuppressFormsAuthenticationRedirectModule.SuppressAuthenticationRedirect(Me.Context, False)
    End Sub
End Class
于 2012-09-11T13:03:58.310 回答