Übersetzung vorschlagen
 
Andere Vorschläge:

progress indicator
Keine anderen Vorschläge
Per Mausklick bewerten und Feedback geben
MSDN
MSDN Library
.NET Entwicklung
.NET Framework 4
System.Web-Namespaces
System.Web
HttpResponse-Klasse
HttpResponse-Methoden
Redirect-Methode
 Redirect-Methode (String, Boolean)
Alle reduzieren/Alle erweitern Alle reduzieren
Inhalt anzeigen:  Englisch mit deutscher ÜbersetzungInhalt anzeigen: Englisch mit deutscher Übersetzung
.NET Framework Class Library
HttpResponse..::.Redirect Method (String, Boolean)

Updated: May 2011

Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public Sub Redirect ( _
    url As String, _
    endResponse As Boolean _
)
C#
public void Redirect(
    string url,
    bool endResponse
)
Visual C++
public:
void Redirect(
    String^ url, 
    bool endResponse
)
F#
member Redirect : 
        url:string * 
        endResponse:bool -> unit 

Parameters

url
Type: System..::.String
The location of the target.
endResponse
Type: System..::.Boolean
Indicates whether execution of the current page should terminate.
ExceptionCondition
ArgumentNullException

url is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentException

url contains a newline character.

HttpException

A redirection is attempted after the HTTP headers have been sent.

ApplicationException

The page request is the result of a callback.

An absolute URL (for example, http://www.contoso.com/default.aspx) or a relative URL (for example, Default.aspx) can be specified for the target location but some browsers may reject a relative URL.

When you use this method in a page handler to terminate a request for one page and start a new request for another page, set endResponse to false and then call the CompleteRequest()()() method. If you specify true for the endResponse parameter, this method calls the End method for the original request, which throws a ThreadAbortException exception when it completes. This exception has a detrimental effect on Web application performance, which is why passing false for the endResponse parameter is recommended. For more information, see the End method.

NoteNote

For mobile pages, if your application relies on cookieless sessions, or might receive requests from mobile devices that require cookieless sessions, using a tilde (~) in a path can create a new session and potentially lose session data. To set a property on a mobile control with a path such as "~/path", resolve the path using ResolveUrl "~/path" before assigning it to the property.

ASP.NET performs the redirection by returning a 302 HTTP status code. An alternative way to transfer control to another page is the Transfer()()() method. The Transfer()()() method is typically more efficient because it does not cause a round trip to the client. For more information, see How to: Redirect Users to Another Page.

The following example uses the IsClientConnected property to check whether the client that is requesting the page remains connected to the server. If IsClientConnected is true, the code calls the Redirect method, and the client will view another page. If IsClientConnected is false, then the code calls the End method and all page processing is terminated.

Visual Basic
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Private Sub Page_Load(sender As Object, e As EventArgs)

        ' Check whether the browser remains
        ' connected to the server.
        If (Response.IsClientConnected) Then

            ' If still connected, redirect
            ' to another page.             
            Response.Redirect("Page2VB.aspx", false)
        Else
            ' If the browser is not connected
            ' stop all response processing.
            Response.End()
        End If
    End Sub
</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
C#
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    private void Page_Load(object sender, EventArgs e)
    {
        // Check whether the browser remains
        // connected to the server.
        if (Response.IsClientConnected)
        {
            // If still connected, redirect
            // to another page. 
            Response.Redirect("Page2CS.aspx", false);
        }
        else
        {
            // If the browser is not connected
            // stop all response processing.
            Response.End();
        }
    }

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Date

History

Reason

May 2011

Added a note about Reponse.Redirect as an alternative.

Customer feedback.

.NET Framework-Klassenbibliothek
HttpResponse..::.Redirect-Methode (String, Boolean)

Leitet einen Client zu einer neuen URL um. Gibt die neue URL an und meldet, ob die Ausführung der aktuellen Seite beendet werden soll.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public Sub Redirect ( _
    url As String, _
    endResponse As Boolean _
)
C#
public void Redirect(
    string url,
    bool endResponse
)
Visual C++
public:
void Redirect(
    String^ url, 
    bool endResponse
)
F#
member Redirect : 
        url:string * 
        endResponse:bool -> unit 

Parameter

url
Typ: System..::.String
Der Zielspeicherort.
endResponse
Typ: System..::.Boolean
Gibt an, ob die Ausführung der aktuellen Seite beendet werden soll.
AusnahmeBedingung
ArgumentNullException

url hat den Wert nullNothingnullptrNULL-Verweis (Nothing in Visual Basic).

ArgumentException

url enthält ein Zeilenumbruchzeichen.

HttpException

Es wurde eine Umleitung nach dem Senden der HTTP-Header versucht.

ApplicationException

Die Seitenanforderung ist das Ergebnis eines Rückrufs.

Als Ziel kann eine absolute URL (z. B. http://www.contoso.com/default.aspx) oder eine relative URL (z. B. Default.aspx) festgelegt werden, doch wird eine relative URL möglicherweise von einigen Browsern nicht akzeptiert.

Wenn Sie mit dieser Methode in einem Seitenhandler eine Anforderung für eine Seite beenden und eine neue Anforderung für eine andere Seite starten, legen Sie endResponse auf false fest, und rufen Sie dann die CompleteRequest()()()-Methodenüberladung auf. Wenn Sie true für den endResponse-Parameter angeben, ruft diese Methode die End-Methode für die ursprüngliche Anforderung auf, wodurch eine ThreadAbortException-Ausnahme beim Abschluss ausgelöst wird. Diese Ausnahme hat negative Auswirkungen auf die Webanwendungsleistung, weswegen das Übergeben von false für den endResponse-Parameter empfohlen wird. Weitere Informationen finden Sie unter der End-Methode.

HinweisHinweis

Folgendes gilt nur für mobile Seiten: Wenn die Anwendung auf Sitzungen ohne Cookies beruht oder Anforderungen von mobilen Geräten erhält, für die Sitzungen ohne Cookies erforderlich sind, kann die Verwendung einer Tilde (~) in einem Pfad dazu führen, dass unbeabsichtigt eine neue Sitzung erstellt wird und möglicherweise Sitzungsdaten verloren gehen. Um eine Eigenschaft eines mobilen Steuerelements mit einem Pfad wie "~/path" festzulegen, lösen Sie den Pfad mit ResolveUrl "~/path" auf, bevor Sie ihn der Eigenschaft zuweisen.

ASP.NET führt die Umleitung aus, indem es einen HTTP-Statuscode 302 zurückgibt. Eine alternative Möglichkeit, Steuerelemente auf eine andere Seite zu übertragen, ist die Transfer()()()-Methode. Die Transfer()()()-Methode ist in der Regel effizienter, da sie keinen Roundtrip zum Client verursacht. Weitere Informationen finden Sie unter Gewusst wie: Umleiten von Benutzern auf eine andere Seite.

Im folgenden Beispiel wird mithilfe der IsClientConnected-Eigenschaft überprüft, ob die Verbindung des Clients, der die Seite anfordert, mit dem Server erhalten bleibt. Wenn IsClientConnected den Wert true aufweist, wird im Code die Redirect-Methode aufgerufen, und für den Client wird eine andere Seite angezeigt. Wenn IsClientConnected den Wert false aufweist, wird im Code die End-Methode aufgerufen, und die Seitenverarbeitung wird beendet.

Visual Basic
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Private Sub Page_Load(sender As Object, e As EventArgs)

        ' Check whether the browser remains
        ' connected to the server.
        If (Response.IsClientConnected) Then

            ' If still connected, redirect
            ' to another page.             
            Response.Redirect("Page2VB.aspx", false)
        Else
            ' If the browser is not connected
            ' stop all response processing.
            Response.End()
        End If
    End Sub
</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
C#
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    private void Page_Load(object sender, EventArgs e)
    {
        // Check whether the browser remains
        // connected to the server.
        if (Response.IsClientConnected)
        {
            // If still connected, redirect
            // to another page. 
            Response.Redirect("Page2CS.aspx", false);
        }
        else
        {
            // If the browser is not connected
            // stop all response processing.
            Response.End();
        }
    }

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

.NET Framework

Unterstützt in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 oder höher, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core wird nicht unterstützt), Windows Server 2008 R2 (Server Core wird mit SP1 oder höher unterstützt), Windows Server 2003 SP2

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.

Datum

Versionsgeschichte

Grund

Mai 2011

Ein Hinweis zu Reponse.Redirect wurde als Alternative hinzugefügt.

Kundenfeedback.

Communityinhalt   Was ist Community Content?
Neuen Inhalt hinzufügen RSS  Anmerkungen
Processing
© 2012 Microsoft. Alle Rechte vorbehalten. Nutzungsbedingungen | Markenzeichen | Informationen zur Datensicherheit
Page view tracker