开发者

Response.Redirect from one web project to another in Visual Studio

I am attempting to integrate a project into a pre-existing solution.

The start-up project in the solution is named "Foo." It is written to the virtual path "/csweb/." When this project starts up it loads /csweb/Default.aspx. This is the current, unmodified home page.

I am attempting to redirect to a different home page in a different project.

I added a second project to the solution named "Bar." Under its project properties I told it to write to the virtual path "/csweb/." It is not marked as the start-up project, nor are there multiple start-up projects -- just Foo. Bar's homepage is accessible when Bar is marked as the start-up project. It's homepage is represented by localhost:port/csweb/Default.aspx

I would like to redirect to Bar's Default.aspx while using Foo as the start-up project. I am fine with renaming Bar's Default.aspx to something non-ambiguous, if that would make the problem easier.

If I try HttpContext.Response.Redirect("~/Default.aspx") then it clearly takes me to Foo/Default.aspx and not Bar/Default.aspx, but the url in the browser is just localhost:port/csweb/Default.aspx. There is no indication of being inside of a project, completely understandable. If I rename Bar/Default.aspx to Bar/UniqueName.aspx and attempt HttpContext.Response.Redirect("~/UniqueName.aspx") then the page is not found.

What's the right call here? Do I need to setup Bar as a pre-existing virtual directory in IIS so that I can specify a more complete path name to avoid ambiguity? Or do I need to do something fancy with multiple s开发者_如何学JAVAtart-up web projects in order for it to be accessible?

Thanks for any advice on this confusing issue.

EDIT: I ended up just adding another folder to Foo's project and moving the contents of Bar's project to this folder. I am then able to do HttpContext.Response.Redirect("~/Bar/Bar's Default.aspx") I'd still love to hear a better solution than this, though!


Try HttpContext.Response.Redirect("/csweb/Default.aspx"). The tilde "~" in your current redirect says to start in this application's home folder. By removing that you can redirect to some other location on your site.

You can also fully qualify the redirect to go to an entirely different site if you wish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜