Redirecting in multiple projects in one solution
.net, asp.net, c#
Solution
To redirect, I suggest adding a setting in your app settings, that specifies the host of Project 2:
<appSettings>
<add key="Project2Host" value="localhost:5571/" />
</appSettings>
Now for the redirect, you can write:
Response.Redirect(Request.Url.Scheme + "://"
+ ConfigurationManager.AppSettings["Project2Host"]
+ "Numbers.aspx");
That way, when it comes time to deploy to a server, you can (hopefully) easily wire it up by simply changing the "Project2Host" setting in the web.config to "MyServer.com/Project2", or whatever.
For the second part, transferring a session variable, maybe you could pass it as a query string? Redirect to the target URL plus `"?Variable=" + Session["Variable"]`. Then pick it up in Project 2 using `Session["Variable"] = Request.QueryString["Variable"];`.
As a footnote: if you're planning to share data between the two sites, I'd consider setting them up as separate folders/virtual directories under the same web application project.
Problem
In my C# Web Application, I have two different projects ("Project1" and "Project2") in one solution. In "Project1" I have a webpage with a button and on the OnClick event I am trying to capture a session variable and redirect to a webpage in "Project2" called "Numbers.aspx". I set "Project1" to include "Project2" as a dependency and "Project1" is the startup project. When I run "Project1" it goes to the following url: ``` http://localhost:5243/WebpageA.aspx ``` When I set "Project2" as the startup project and run it, it goes to the following url: ``` http://localhost:5571/Numbers.aspx ``` In "Project1" when I write: ``` Response.Redirect("~/Numbers.aspx"); ``` it says the path is not valid. I also tried the following path and it says it does not exist: ``` Response.Redirect("~/Project2/Numbers.aspx"); ``` Does anyone have any suggestions how I can redirect to this webpage in the different project and capture a session variable from Project1? Thanks! ``` //OnClick event protected void click(object sender, EventArgs e) { Session["Variable"] = textBoxName.Text; } ```