James123
James123

Reputation: 11652

how to redirect to root file in asp.net?

My loging page in root/Account/Login.aspx page when I click on contact us i need to redirect to root/contactus.aspx page. I used Response.Redirect("~/contactus.aspx") in Master page (Site.Master)

 Protected Sub lbContactUs_Click(sender As Object, e As EventArgs) Handles lbContactUs.Click
    Response.Redirect("~/contactus.aspx")

End Sub

Still it is not redirecting to page.

enter image description here

Upvotes: 1

Views: 10272

Answers (3)

Jason Kulatunga
Jason Kulatunga

Reputation: 5894

Add the following to your web.config

<configuration>
...
<location path="ContactUs.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
... 
</configuration>

It seems that you have a deny all anonymous users rule set in your web.config. If you need to allow anonymous users access to specific pages, while still leaving the rest of your site protected by forms authentication, you can use the location tag to override the security for specific pages.

Upvotes: 4

David East
David East

Reputation: 32604

You are not redirecting properly.

Response.Redirect("/contactus.aspx", False);
Context.ApplicationInstance.CompleteRequest();

Do not use Response.Redirect(url). It calls Response.End which is very taxing on the server.

Response.Redirect(url, false) is much faster and more efficient.

Response.End will raise a ThreadAbortException which costs a lot for the server to do.

http://blogs.msdn.com/b/tmarq/archive/2009/06/25/correct-use-of-system-web-httpresponse-redirect.aspx

@Jason Kulatunga's answer looks like it will solve your problem. The above information is just for good practice.

Upvotes: 6

R.D.
R.D.

Reputation: 7403

@James123: Use

 Protected Sub lbContactUs_Click(sender As Object, e As EventArgs) Handles lbContactUs.Click
 Response.Redirect("/contactus.aspx")

End Sub

this will redirect to root directory

Upvotes: 1

Related Questions