Srinivas Mantha
asked on
ASP.NET C# code for Page direction dynamically based on database value
I am designing a web application on ASP.NET with C# code.
I wish to redirect to respective homepages based on userids. The userlogin table has a field “pagedirection” to indicate the page for redirection. For example,
for “visitor” userid the pagedirection value is
"../visitor/visitorhomepag e.aspx"
In the usual non-dynamic mode one uses the following code
Response.Redirect("../visi tor/visito rhomepage. aspx");
The following code to redirect dynamically is not working.
Response.Redirect(dbreader ["pagedire ction"].To String());
Can anyone modify the code to get the results that I desire.
I wish to redirect to respective homepages based on userids. The userlogin table has a field “pagedirection” to indicate the page for redirection. For example,
for “visitor” userid the pagedirection value is
"../visitor/visitorhomepag
In the usual non-dynamic mode one uses the following code
Response.Redirect("../visi
The following code to redirect dynamically is not working.
Response.Redirect(dbreader
Can anyone modify the code to get the results that I desire.
ASKER
The url is returning the expected value at breakpoint i.e.
"../visitor/visitorhomepag e.aspx"
However at the end the following error message is displayed:
Server Error in '/websitesmnew' Application.
HTTP Error 400 - Bad Request.
"../visitor/visitorhomepag
However at the end the following error message is displayed:
Server Error in '/websitesmnew' Application.
HTTP Error 400 - Bad Request.
And what do you see in the address bar for url when the error is thrown?
ASKER
I am seeing the following in the address bar
http://localhost:49212/websitesmnew/smnew/%22../visitor/visitorhomepage.aspx%22
when I commented the dyanamic mode and activated nondynamic mode, it is directed to the correct desired page in which address bar is displaying
http://localhost:49212/websitesmnew/visitor/visitorhomepage.aspx
http://localhost:49212/websitesmnew/smnew/%22../visitor/visitorhomepage.aspx%22
when I commented the dyanamic mode and activated nondynamic mode, it is directed to the correct desired page in which address bar is displaying
http://localhost:49212/websitesmnew/visitor/visitorhomepage.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the accurate solution
Add this and set a breakpoint and see:
string url = dbreader["pagedirection"].
Response.Redirect(url); //set a breakpoint and see what is the url that you are getting?
most likely you will need to have your url in ~/ format.