我正在使用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
答案 0 :(得分: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