Solved

ASP.NET C# code for Page direction dynamically  based on database value

Posted on 2013-01-25
6
345 Views
Last Modified: 2013-01-26
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/visitorhomepage.aspx"
In the usual non-dynamic mode one uses the following code
Response.Redirect("../visitor/visitorhomepage.aspx");

The following code to redirect dynamically is not working.
Response.Redirect(dbreader["pagedirection"].ToString());

 Can anyone modify the code to get the results that I desire.
0
Comment
Question by:smanthanims
  • 3
  • 3
6 Comments
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
I would first see if the correct value is returned for pagedirection.
Add this and set a breakpoint and see:

string url  = dbreader["pagedirection"].ToString();
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.
0
 

Author Comment

by:smanthanims
Comment Utility
The url is returning the expected value at breakpoint i.e.
"../visitor/visitorhomepage.aspx"
However at the end the following error message is displayed:

Server Error in '/websitesmnew' Application.
HTTP Error 400 - Bad Request.
0
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
And what do you see in the address bar for url when the error is thrown?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:smanthanims
Comment Utility
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
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 250 total points
Comment Utility
ok so you need to remove the " (double quotes) and .. from your url and add a ~ before doing a Redirect.

I would suggest you to store url without " and .. in your db e.g.
 /visitor/visitorhomepage.aspx

string url  = dbreader["pagedirection"].ToString();
Response.Redirect("~/" + url.TrimStart('/'));
0
 

Author Closing Comment

by:smanthanims
Comment Utility
Thank you for the accurate solution
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now