Solved

Showing different pages with the same url

Posted on 2013-06-13
7
330 Views
Last Modified: 2013-06-23
How can I show a different webpage for different users on the same URL?

e.g.
A user that is logged in will see different contents from a user that is not logged in. And no, I don't want to redirect users that are not logged in to a log-in page. I also don't want to just hide/show a few controls since that contents could be completely different.
0
Comment
Question by:Thomasian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 20

Expert Comment

by:n2fc
ID: 39246471
When a user logs in, set a cookie with a short expiry time...

Then you can query the cookie & display content based upon their login status...

Of course, this will require that your users permit cookies!
0
 
LVL 22

Author Comment

by:Thomasian
ID: 39246480
>>display content based upon their login status.

This is the question. How do I change/select the page to display with the same URL?

e.g.
If a user is logged in, show index1.aspx
If a user is not logged in show index2.aspx.

I have no problem checking the log in status of the user. What I want to know is how to show a different page using the same url.

Note: I do NOT want to redirect the user to a different address.
0
 
LVL 20

Expert Comment

by:n2fc
ID: 39246524
Following reference shows how to set & test cookies as well as conditional code:

http://www.quirksmode.org/js/cookies.html

Look for the section named readCookie...
where it says:
var x = readCookie('ppkcookie1')
if (x) {
	[do something with x]
}

Open in new window

replace "do something with x" (you can have one page's code)
and add an "else" clause for the opposite condition...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Author Comment

by:Thomasian
ID: 39246552
>>replace "do something with x" (you can have one page's code)

My question is about the "do something" after the If statement.

Sorry if my question was not clear, so let me rephrase the question:

Let's say I want to show a different page on my homepage depending on the time of the day.

If time is between 0:00 to 11:59, show "AMPage.aspx" on my homepage. If time is between 12:00 to 23:59, show "PMPage.aspx" on my homepage.

Note: I do not want to redirect it to a different address.
0
 
LVL 4

Accepted Solution

by:
jiangsheng earned 500 total points
ID: 39254200
>I do not want to redirect it to a different address.
use Server.Transfer instead of Server.Redirect
Hard for debugging though, you now get multiple pages on the same url.
0
 
LVL 22

Author Comment

by:Thomasian
ID: 39255006
Is this how it is usually done? I think that it is a common situation to show a different site for guest and logged-in users.

e.g. experts-exchange.com

Also, is it possible to deny access to some pages by directly typing in the URL? i.e. I don't want to allow access to AMPage.aspx by directly typing in "http://mysite.com/AMPage.aspx"
0
 
LVL 4

Assisted Solution

by:jiangsheng
jiangsheng earned 500 total points
ID: 39262713
No, this is not the way it is usually done. The usually way is to use the LoginView control or check HttpContext.User.Identity.IsAuthenticated in the MVC controller to have the same page displaying different views. See How to: Display Different Information to Anonymous and Logged-in Users
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
history of pages 7 55
Pass a js value to an html form 5 43
search by any word in column 5 29
web api controller with multiple posts that accept different objects 1 26
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

710 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