I know how to password protect a page and check if it has been entered with post_password_required. What I need to know is if I can then continue to know if a user has logged into this password protected page even after leaving it. The reason for this is because I would like to display a site wide navigational sidebar that allows the user to get back to that page, but only have it show if they have logged into that page earlier.
Set a session variable if they login successively to the given page, then when they are on another page later, have the sidebar echo the link if that session var is set.
The value of the session var can be the url to create the link, if you have more than one page you're trying to do this with.
Related
There is some generated contents with the links on an ASP.NET page, which is created after the user inputs values and hits a button. The links take the user to another page.
When the user hits the Back button, the generated content is gone as the page returns to its initial state with the inputs cleared and generated content not there.
Is it possible to preserve the state of the page after its content has been generated and restore it after the Back button was clicked?
I think you can you can you temporary cookies.
and on load check whether cookie is exists or not.
Save the inputs in the session, so that the page will know how to correctly render on later requests. Even better, have the first code that runs when the data is submitted redirect to new page with a URL parameter that you use to know which links to show. This is a called a POST-REDIRECT-GET pattern.
I am working on asp.net application.the user is clicks on some link which is inside grid item template field. if he is not logged in then he redirects to login page. after log in he is properly coming back to same page;the problem is that "i have passed the value in querystring to the page where he click on the link and after loggedIn the grid is showing blank because that grid is not getting query string value" I think you understand my problem.plz share your helpful opinion.
http://www.aspdotnetfaq.com/Faq/what-is-the-difference-between-server-transfer-and-response-redirect-methods.aspx
It is not a defect, but the desired behavior of Response.Redirect.
Store value in session and retrieve it after he gets back successfully from the login page.
I am using ASP.NET to submit data from a form to a database.
But before submit I want to check if the current user us valid. If not I want to use the login control registration form where an existing user can enter his user id and password then go back to the previous page to submit the form data.
Example:
Assume a page having 3 textboxes and one button. Once the user clicks the button I want to check if the user is already logged in or not. If not I want to open the login page so he can provide his credentials and after that execute the previous page submit function without the user having to click again.
I think you're asking about form validation? The easiest way to do this is with a postback. Put a button on the form, that button will post back the form to itself, and fire the button_Click event. Inside that event you can put some C# code that will validate the user's name and password. Then you can show a label on the form that indicates the credentials are not correct.
Hope that helps!
You can save information about user, using session:
Session["UserLoggedIn"] = true;
When you want to check, if user is logged in, check like this:
if(Session["UserLoggedIn"] != null)
{
// User is logged in
}
else
{
// User is not logged in, so redirect to login page
Response.Redirect("~/login.aspx");
}
if you want to redirect back, after successful log in operation. you can use QueryString. So instead of:
Response.Redirect("~/login.aspx");
redirection will be:
Response.Redirect("~/login.aspx?RedirectUrl=your current form url");
In login page, you can read QueryString:
string redirectUrl = Request.QueryString["RedirectUrl"];
After login operation, use redirectUrl value, to redirect back:
Response.Redirect(redirectUrl);
i hope i have tried to understand you.
firstly, i would like to explain what you want.
You want to check user logged in before submit, and if he is not logged in you want him to redirect to login page after he logs in u want to come back on the same page. and perform your click function.
RetrunUrl
return url in your querystring will help to return to back to your original page. and u can save the details of the previous page in session and once user logs in and redirects back to original back perform your click event there. by validating you session value,
once you are done with your whole process remember to abandon your current session details
I set a src attribute of an iframe as a home page, so after login we redirect the user to the home page.
When the user navigates around it is fine, but the problem comes when the user uses the F5 key on the keyboard as a refresh button.
It refreshes the entire page, which kicks them back to the main page (home page which was set as the src in iframe).
So, I have put the last visited page url in a session variable. But a problem occurs when the last visited page url uses the post method. Then just putting the url in the iframe src does not work as the form has method=post.
this is a common post problem, not related to iframe actually. this is the method i use to prevent this issue:
use posted data (store it to database etc.) and immediately redirect to another page before showing anything on screen. if some data needs to be used on the next page, read it from stored place or use either session or get method to pass to the next page.
that way, you won't have any problems with refreshing the page. you can also store the next page's url to the session variable at the posted page.
I have 3 asp.net pages: Search.aspx, Results.aspx and Login.aspx.
Now I want anonymous users to be able to search, so everyone can use search.aspx. This page calls
Server.Transfer(Results.aspx)
and therefore shows the results. Now when the user is not logged in, a link to the login page is displayed on the Results page. The problem is:
After the login, I want the user to be redirected automatically to the Results page. However I do not succeed so, as the PreviousPage property of Login.aspx is always null. And when I use
Request.UrlReferrer.LocalPath
it's the link to Search.aspx but not Results.aspx.
Also, when the user is on the Results page, how do I enable him to go back by clicking a link and all his search input criteria (like in textboxes) on the Search.aspx is still there so he can refine the search after having seen the results? Whenever I send the user back, all user input is lost.
I still haven't figured out if I should use a normal hyperlink, a linkbutton and how to retrieve the previous page url or preserve the input data.
I can use AJAX if that is any help, but a "pure" asp.net solution would be preferred.
When you do a Server.Transfer it is a serverside redirect...meaning the client still sees the original URL. You need to post the search criteria to the results page, store them locally, show the login link. When they are logged in you can redirect to the results page and rehydrate the search critera and show the results.
Try using Response.Redirect("url") instead of Server.Transfer. When you use Server.Transfer, the url on the client will remain the Search page and not actually redirect to the Results.
You can use User.Identity.IsAuthenticated to check if the user is logged in and show/hide the login button based on that.
To keep values for the page, you could store them in Session, then have the Search page look for them and, if they exist, place them in the controls.
You can also embed the URL you want to return to after login into the querystring if you want.