Reputation: 15400
I have a Web Form whose sole purpose is to redirect to other pages. I created it as a normal aspx page and then I deleted everything in the .aspx file and kept just the first line shown below--even the Doctype and HTML tag are gone now:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Redirect.aspx.cs" Inherits="Web.Redirect" %>
I also deleted the .designer.cs file as it contained nothing. It works, but I wonder if what I did is right. Are there any concerns about removing all HTML content from the Web Form in this case?
Upvotes: 0
Views: 2848
Reputation: 10400
None whatsoever. What you have done is perfectly acceptable.
However, if the sole purpose of the pages is to redirect, I would use a Handler/ASHX file as it can be used in exactly the same way and doesn't have as much overhead as the ASPX page.
Here is a description and example of how to use one.
Upvotes: 2
Reputation: 75619
If you do Response.Redirect(url)
, a redirect header is added and the request is ended. This means that anything in your ASPX page is not output to the client. Any content after Response.Redirect(url) is not output to the page. You can just as well delete it, like you did.
If you do Response.Redirect(url, false)
, the response is not ended and your page is output to the client. However, the client never gets to see it because he is redirected.
Upvotes: 1