Redirect with ASP.NET

On several occasions I have needed to redirect a user from one place to another in ASP.NET. I like to do this with code similar to the following, which doesn’t require code-behind.

<%@ Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","/public/Default.aspx");
}
</script>

<html>
<head runat="server">
    <title>Redirecting...</title>
</head>
<body>
</body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s