How to auto refresh the page only one time? - page-refresh

I've a web page when a user logs in, it will have a link that shows the "username" and a link for "logout".
After the user logs out, the "username" and the "logout" links will change to "login" and "register" links, respectively.
The page uses javascript to check a user cookie, if the user cookie exists, it will show the "username" link and the link for "logout". If no user cookie exists, "login" and "register" links will replace the "username" and "logout" links.
Here's the problem: When a user who has log in, clicks the "logout" link, a perl script will delete the user cookie, and redirects back to the same page. The page does not show "login" and "register" links AUTOMATICALLY. Both links will appear ONLY after the user MANUALLY Refreshes the page.
It appears that I need a system to refresh the page automacally ONLY one time. How can this be done?

you could do it like this
after deconnexion redirect to 'page.html?1'
and in javascript side use this snippet
to check for the ?1 and redirect to 'page.html'
var refreshCheck= Number(window.location.search.slice(1));
if (refreshCheck == 1 ) {
window.location.href = window.location.substring(0, window.location.length-2);
}

I dont think it's good to force a refresh for this kind of things and you should consider the way you are dealing with the operation but if you want the easy way then you have to add this code which will refresh immediately
<meta http-equiv="refresh" content="0">

Related

Redirect visitors to a page saved in cookie

I have a main navigation and
Visitors click the main navigation -- a cookie remembers their last page.
Next time visitors enter the site from the root url they are redirected to that page.
How would you do it?... Any code would be appreciated :)
Save the last location they visited like this, you could probably do this with a simple before filter on your ApplicationController. In it you can add some logic to decide if you want to save the new location or retain the current one.
cookies.permanent[:last_visited_path] = request.request_uri
Then in the action pointed to by your root URL:
if cookies[:last_visited_path].present?
redirect_to cookies[:last_visited_path]
end
You could also look into signing the cookie with cookies.permanent.signed if you want to prevent users from tampering with it.

JSF login forward address bar / url -- redirect does not solve problem

Okay we have a single - sign - on and the user will likely enter www.blabla.com/AppName/ to reach our site. We then define a welcome site, use a phaselistener to check:
is user trying to access the welcome site? yes -> try to login - works? yes -> get user roles -> forward to the appropriate site for this specific user.
E.g. user niceBelly goes to page /somewhere/in/many/folders/beer.jsf and user barbie goes to /breasts/pink.jsf
a redirect is in this application not possible for some reasons.
the result is that when reaching e.g. page pink.jsf the address bar still shows blablaba.com/AppName/
clicking the first link will result in the browser using the form address as new URL e.g. on welcome.jsf i navigate to coolstuff.jsf. On the page coolstuff i now have the url of the last form, e.g. welcome.jsf. Then on cool stuff i click a link, and get coolstuff on the next page as url, and so on.
Is there a way to solve this / work around it?
Given the symptoms, you are actually not redirecting the requests, but you are actually forwarding the requests. A real redirect will take place when you call
externalContext.redirect(url);
in JSF context, or when you add
<redirect />
to the navigation case. All other ways are effectively forwards. As per the symptoms, you're using commandlinks instead of outputlinks to navigate to other page. Commandlinks will submit a POST request to current URL and JSF will under the covers use RequestDispatcher to set the destination of the request/response when the navigation case doesn't contain <redirect />. A forward does not instruct the browser to fire a new GET request on the destination URL and hence the URL in browser address bar does not change. A real redirect will do exactly that.
See also:
When should I use outputlink instead of commandlink?
Bookmarkable URLs in JSF 1.x

redirected to the log in page/Color box

I have a controller that returns
System.Web.Mvc.FilePathResult
I do return this.File(filename, contentType, download name);
This action is called when user is clicked on a link and
I have made $("a[rel='popup']").colorbox();
.So whenever a user clicks on the links
It takes to the controller method and the file
Shown in the colour box.
Now I am facing an issue it is like
If a user is logged in to my site and open a page
, where links are shown and the user goes away from his seat (ie session expires)
Then he come back and clicks on the link
.At that time my application breaks as there is no valid session.
So tried to return View("LogOn");
when session is null.
But as still it is not redirected to the
I think it is because of the colorbox
Can anyone suggest any thing such that I should be redirected to the log in page
Even if I am taking a Color box
?
When a session expires, it will not be "null", so if you're checking if (Session == null), this won't work. You'll need to check for the presence of a session variable instead.
In your comment you say you're tried redirecting to /Home/Login but it doesn't render the login view. Can you elaborate? What does it render?

how to reset page text boxes data after page post back?

my question seems simple and stupid
but first read this,
suppose you have a login form which take username and password and post back to controller
if login successful then return Homepage(return View("HomePage")) View (not Redirect) then suppose i am Logged off
and return Login (return View("Login")) View (again not Redirect) and now if i press Back button and Refresh the page then it will automatically get logged IN by using those username and password which i entered before.
So can i make those password Null from Browser's Memory or where ever it is i don't know.
"i know that not redirecting (RedirectToAction("ViewName")) is causing the problem" But Why or May be i don't know any important concept
Some browsers, especially Firefox try to be helpful and 'remember' values you have input into text fields and checkboxes. in order to switch this off in a particular input add the following attribute
autocomplete="off"
Alternatively, using jQuery you can switch it off for a whole form:
$("form").attr("autocomplete", "off");
ModelState.Remove("key");
or
ModelState.Clear()

ASP.NET MVC - How can I pass FormCollection data in a post to another Action?

I have a page "Results" with a form and when "submit" is clicked, the form is submmited to another Action. So far, so good...
But, this works fine just if user is logged in. If not, he will be redirected to "Login" page and my FormCollection loses its data.
Is there a way to persist this data without using TempData??
Thanks!!
I don't think that's possible. The only thing the system remembers during the redirect to the login page is the 'return url'. No post data is saved (this could be megabytes of data...)
You can use the Session object as alternative, or make sure that the user is logged in before you post.
Or, if it's just a search result, try to live without the POST, and use a GET (which also has other advantages)
I would prefer to disallow unauthorized user to visit "Results" page or at least to show him message "Please login first" instead of the form.

Resources