Reputation: 3991
The scenario is
Project1
webform1.aspx
Project2
webform2.aspx
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.
If i write
Response.Redirect("~/Webform2.aspx"); // the line will throw exception page not found
how to solve this?
Upvotes: 1
Views: 10185
Reputation: 2080
while saw your question i hope you need to get the difference between Response.Redirect and Server.Transfer
Response.Redirect();
Response.Redirect() is used when calling the webpage present in another website i.e; which is not present in our current project.For example
Response.Redirect("http://localhost:1234/Webform2.aspx");
Server.Transfer():
Response.Redirect() is used when calling the webpage present in current website i.e; which is present in our current project.For example
Response.Redirect("~/Webform2.aspx");
it will automatically fetches current project url loc and append it to the webpage.
i.e; http://www.localhost:6789.com/Webform2.aspx
Example :
Project 1:
webpage1.aspx
webpage2.aspx
Project 2:
webpage3.aspx
webpage4.aspx
Say you are in project1 if you redirect from webpage1 to webpage2 use
Server.Transfer(~/webpage2.aspx)
If you want to redirect from webpage1 to webpage3 use
Response.redirect("http://localhost:1234/Webform2.aspx")
For more see : http://www.youtube.com/watch?v=xJVjRUHXYbE
Upvotes: 0
Reputation: 3057
As you said that you have added the reference assembly of Project2 in Project1 that you have added all the dlls of Projects2 in Project1, but have you added the aspx files of project2 in project1???
If not, then add those aspx files from Project2 to Project1 and then use your redirect code with the relative path as
Response.Redirect("~/Webform2.aspx");
Upvotes: 0
Reputation: 11995
Both projects will run as two different servers.
While development, they'd most commonly start with a localhost
followed by a port number. Now your Project1
isn't aware of Project2
.
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
.
Therefore your response.redirect call would be
Response.Redirect("http://localhost:4545/Webform2.aspx");
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)
Upvotes: 2