Skip to main content

AddToAny

Share/Save

301 Redirect in asp.net

2 replies [Last post]
vaibhav
vaibhav's picture
User offline. Last seen 5 days 8 hours ago. Offline
Joined: 08/19/2009

I have just uploaded a new website www.tapasya.co.in. When I tried to access, it showing me a blank page. But when I tried using the complete path of the home page http://www.tapasya.co.in/Web%20Pages/Home.aspx , its working.

I think, I have figured the problem, which might be occuring. I have to put this page at the root folder, to access it using www.tapasya.co.in. But I don't want to put this page at the root folder. I searched it on google, and some solutions says, that I have to do a 301 redirect.

But I dont know how to do that. Please help, thanks in advance.

Anonymous
Anonymous's picture
If you really want your Pages

If you really want your Pages to be located in "Web Pages" then add this Default.aspx in your root folder:

<%@ 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"> 
    void Page_Load(object sender, EventArgs e) 
    { 
        Response.Redirect("Web Pages/Home.aspx"); 
    } 
</script> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
        <a href="Web Pages/Home.aspx">Redirect</a> 
    </form> 
</body> 
</html>
vaibhav
vaibhav's picture
User offline. Last seen 5 days 8 hours ago. Offline
Joined: 08/19/2009
@above This is a not

@above

This is a not 301 Redirect, but a 302 Redirect.

301 Redirect is

 

private void Page_Load(object sender, System.EventArgs e) 
{ 
    Response.Status = "301 Moved Permanently"; 
    Response.AddHeader("Location","http://www.aspcode.net/newpage"); 
}