Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have some code in a the Page_Init event of a web page (actually, it is in the .master Page_Init), which uses Server.Transfer() to try to go to another page under certain circumstances. When I run it, the transfer is ignored and control comes straight back to the calling page (like a normal postback for a button).

I'm obviously missing something obvious here. I'd be extremely grateful if anyone could tell me what I am doing wrong.

Kind wishes ~ Patrick

C#
protected void Page_Init( object sender, EventArgs e )
{
        Server.Transfer( @"\Default.aspx" );
}
Posted
Comments
idenizeni 29-Aug-13 21:38pm    
I'm curious why you are trying to do this, what is your goal. There may be a better way to do what you are ultimately trying to do.
Patrick Skelton 30-Aug-13 4:47am    
Hi,

There is definitely a better way to do it. I am implementing a basic quick-and-dirty security system on a prototype website. I don't have the luxury of using the out-of-the-box ASP.NET controls because I don't have permission to run aspnet_regsql.exe on the host server, and I wanted to do something quicker than figuring out how to write my own role provider and creating my own database tables. What I need is a simple true/false access for the page, not roles or permission sets or anything. I may end up having to do a 'proper' system. But even if I do, I'd still be very interested to know what is going wrong with this Server.Transfer().

Out of interest, are there any alternatives? I was thinking I may be able to raise an HTTP error, and specify a default redirect in the Web.config. Again a dirty solution, but is such a thing possible?

Kind wishes ~ Patrick
idenizeni 30-Aug-13 11:59am    
Try using the below code in the Page_Load of the master page, I don't think you want to use Server.Transfer() if you are trying to prevent access to a page.

Response.Redirect(ResolveUrl("~/") + "Default.aspx");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900