c# - Redirecting in multiple projects in one solution -


in c# web application, have 2 different projects ("project1" , "project2") in 1 solution. in "project1" have webpage button , on onclick event trying capture session variable , redirect webpage in "project2" called "numbers.aspx". set "project1" include "project2" dependency , "project1" startup project. when run "project1" goes following url:

http://localhost:5243/webpagea.aspx 

when set "project2" startup project , run it, goes following url:

http://localhost:5571/numbers.aspx 

in "project1" when write:

response.redirect("~/numbers.aspx"); 

it says path not valid. tried following path , says not exist:

 response.redirect("~/project2/numbers.aspx"); 

does have suggestions how can redirect webpage in different project , capture session variable project1? thanks!

   //onclick event     protected void click(object sender, eventargs e)     {         session["variable"] = textboxname.text;     } 

to redirect, suggest adding setting in app settings, specifies host of project 2:

<appsettings>     <add key="project2host" value="localhost:5571/" /> </appsettings> 

now redirect, can write:

response.redirect(request.url.scheme + "://"      + configurationmanager.appsettings["project2host"]      + "numbers.aspx"); 

that way, when comes time deploy server, can (hopefully) wire changing "project2host" setting in web.config "myserver.com/project2", or whatever.


for second part, transferring session variable, maybe pass query string? redirect target url plus "?variable=" + session["variable"]. pick in project 2 using session["variable"] = request.querystring["variable"];.


as footnote: if you're planning share data between 2 sites, i'd consider setting them separate folders/virtual directories under same web application project.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -