How to Server.Transfer from a standalone page?

2019-09-07 10:40发布

I have a page in a folder on a site, and I want to Server.Transfer to it from the domain root. I tried adding a page to the root containing:

Server.Transfer("~/folder1/default.aspx");

But I get a 500 error. I also tried

Server.Transfer("/folder1/default.aspx");

With the same result. But when I tried Server.Transfer("default2.aspx"); - another page in the root, it worked.

So how do I transfer to the page I want to transfer to?

EDIT: folder1 is a web application (Asp.net) - does it matter?

1条回答
beautiful°
2楼-- · 2019-09-07 11:05

Yes - it matters that folder1 is a separate application in its own right.

Server.Transfer is only meant for transfers within your own ASP.NET application as it directly instantiates the target page and sends the response back from where it was called. It has no way of doing this across applications.

It will be better for you to perform a simple Response.Redirect to the /folder1/default.aspx page instead of transferring there.

Edit: In the Page_Load of your Default.aspx (root), add

Response.Redirect("/folder1/Default.aspx");
查看更多
登录 后发表回答