如何在asp.net的另一个解决方案中重定向到另一个页面? [英] How to Redirect to another Page in another solution in asp.net?

查看:57
本文介绍了如何在asp.net的另一个解决方案中重定向到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景是

  • Project1
    webform1.aspx

  • Project1
    webform1.aspx

Project2
webform2.aspx

Project2
webform2.aspx

在按钮上单击webform1,它必须 Response.Redirect()到webform2.我添加了参考程序集,但不知道如何传输.

On button click in webform1 it has to Response.Redirect() to the webform2. I have added the reference assembly but could not figure out how to transfer.

如果我写

Response.Redirect(〜/Webform2.aspx");//该行将抛出未找到的异常页面

Response.Redirect("~/Webform2.aspx"); // the line will throw exception page not found

如何解决这个问题?

推荐答案

两个项目都将作为两个不同的服务器运行.

Both projects will run as two different servers.

在开发过程中,它们通常以 localhost 开头,后跟端口号.现在您的 Project1 不知道 Project2 .

While development, they'd most commonly start with a localhost followed by a port number. Now your Project1 isn't aware of Project2.

这意味着您必须在Response.Redirect调用中手动提供完整的URL.假设您的 Project2 托管在 http://localhost:4545 上.第二个Web表单的url为 http://localhost:4545/Webform2.aspx .

This means you'd have to manually provide the full url in the Response.Redirect call. Say your Project2 is hosted at http://localhost:4545. The url of the 2nd web form would be http://localhost:4545/Webform2.aspx.

因此,您的response.redirect调用将为

Therefore your response.redirect call would be

Response.Redirect("http://localhost:4545/Webform2.aspx");

因此,您必须手动对其进行硬编码.另外,您可以考虑通过从配置设置(web.config)中获取此值来使其动态化.

So you'd have to manually hard-code it. Else you can think of making it dynamic via fetching this value from the configuration settings (web.config)

这篇关于如何在asp.net的另一个解决方案中重定向到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆