1

一部のHTTP401のリダイレクトを防ぐために、 http://haacked.com/archive/2011/10/04/prevent-forms-authentication-login-page-redirect-when-you-donrsquot-want.aspxにあるSuppressFormsAuthenticationRedirectModuleを使用しています。ステータスを設定し、代わりにカスタムページを表示します。

ただし、出力としてObjectMovedHereを取得しています。代わりにカスタムページを表示するにはどうすればよいですか?

次のようなページ

<%@ 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 に答える