How to Server.Transfer from a standalone page?

元气小坏坏 提交于 2019-12-12 03:48:48

问题


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:


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");


来源:https://stackoverflow.com/questions/13633316/how-to-server-transfer-from-a-standalone-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!