I am implementing ASP.NET User Membership authentication in a website.
I am using ASP.NET's control to
authenticate user,
sign up new user and
change password to change the authenticated user's password.
My functionality is:
On Sign Up page, I have User name and Email as inputs and I have set theAutoGeneratePassword property to true.
Once successful registration system sends out an email to that user with a URL in email (like http://localhost:xxxx/Login.aspx?user=abc10&pwd=something).
My issue is, when user clicks above link, he should be redirected automatically to change password page to change the password.
So, for redirection, I am trying to call the OnLoggedIn event in page_Load.
I have tried below calls from page_Load event.
Login1_LoggedIn(sender.GetType(), null)
login.LoggedIn += new EventHandler(Login1_LoggedIn)
But the event is not firing, can anybody help?
Finally I figured that out. As I had to work out two scenarios,
I. The user should be able to login from the login page.
II. And when user should be able to redirect to next page following login when he/she clicks the link they have received in their email.
So the first point is very straight forward.
For the second point, I created a method which has all code logic to authenticate the user. And called this method in page_load() event and from OnLoggedIn event.
And in page load, I wrote below code to simulate login event to redirect user directly to next page.
protected void Page_Load(object sender,EventArgs e)
{
string username = usernameTextbox.Text.Trim();
**FormsAuthentication.SetAuthCookie(username, true);**
callLogin();// this method where in my user authentication logic resides
}
Related
First of all, I can't use Async plugins like Jquery, Ajax, UpdatePanel, etc.
I have an ASP.NET 4 WEBFORM, In the master page I verify if the Session is lost, in that case a show a modal to get the username/password and log-in the user again.
But I've two problems, the first one is that for example if I press a button and I lost the session, the webpage show me the modal but the code behind of the clickevent still execute it and i want to prevent it (I dont want to verify the state of the session in every event handler of the APP).
The second one is that after Im success on log-in the user, i want to finish or continue the event that the user tries before he lost the session.
I other words my problem is that I need to prevent the postback in the middle of it, and then do it again. :/
Something like this:
Page_Load(...)
{
If(Session["User"] == null)
{
PostBack.Cancel(); //Like de e.PreventDefault() of Javascript.
return;
}
.
.
}
AND
LoginOnSessionLost()
{
...
//After Login Success
Postback.Continue();
}
Any suggestions? Thanks
I am developing a application in asp .net 4.0.
Here when I am logged in to my application, go to inner pages, say "Manage Role" and copy the link and click on Logout button it displays my login page. Now i paste that link in another tab and expect it to display me the login page but it does not happen, it shows me Manage Role page.
So please give me some solution, how can i show login page in this case?
you have to use session variables to check whether the user is logged in or not and thenin each of ur pages..in the page load event u have to check whether that session user variable is null or not if null den redirect it to login page
Try using Session Destroy function available in ASP.Net
if you are using C#
try:
Session.Abandon();
If you want to remove a specific item from the session use (MSDN):
Session.Remove("YourItem");
EDIT: If you just want to clear a value you can do:
Session["YourItem"] = null;
If you want to clear all keys do:
Session.Clear();
And Then Check for Session Value on every page you want to restrict only with Session Access(for Logged In User).
In Your page "Manage Role",In Your Page load, Check that user info is available or not in the session.
and When you Click on log out button,First Remove User Information from Session and then Redirect it Login Page.
First Remove All Session on logout button click event
Session.Abandon();
Session["SessionName"] = null;
Session.Clear();
Then Write Code in Global.asax File
Void Application_Error(object sender,EventArgs e)
{
Response.Redirect("LogIn.aspx");
or
Server.Transfer("LogIn.aspx");
}
I have created a c# windows application that have provided text box for user id and password and upon clicking submit button it will automatically log-in an eBay account to www.ebay.com using webbrowser component. Logging in seems to be easy if the inputted username and password was correct. And now what i want to accomplish with your kind help is:
Every time the user inputs a wrong username or password on the windows application a message box will notify the user that the username and password was incorrect. And that the logging in to the website was unsuccessful.
Here is my code for WebBrowser's event DocumentComplete.
//webTest is the name of my web browser
private void webTest_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//boolean login variable checks if the button login was clicked.
if (login == true)
{
//checks if the url is on the login page of eBay.
if (webTest.Url.AbsoluteUri == loginPage)
{
HtmlDocument doc = webTest.Document;
HtmlElement username = doc.GetElementById("userid");
HtmlElement password = doc.GetElementById("pass");
HtmlElement submit = doc.GetElementById("but_sgnBt");
username.SetAttribute("value", txtUser.Text);
password.SetAttribute("value", txtPassword.Text);
submit.InvokeMember("click");
login = false;
}
//else the webbrowser webtest will navigate to the login page,
else
webTest.Navigate(loginPage);
}
}
Thank you for all the reply i really appreciate it. May God Bless c#!
Since webTest_DocumentCompleted will be called whenever a page is fully loaded, you should be able to detect if you were redirected from the login page to another page. For instance, the login page for eBay UK is located on the domain https://signin.ebay.co.uk/. A successful login transfers me to http://my.ebay.co.uk/ instead.
You could check for this transfer in the webTest_DocumentCompleted method. If it did happen, you were logged in. If not, you were not logged in (and can show a message box to alert the user).
I have a website, in which a user Logs in. I am using an asp:Login. The login page works fine, but i have associated an event handler that when the user logs in the site will get redirected to an authentication page which will send the Username in this manner.
protected void LoginUserPass_LoggingIn(object sender, LoginCancelEventArgs e)
{
Response.Redirect("~/Authenticate.aspx?user=" + LoginUserPass.UserName);
}
And the i have set the DestinationPageUrl of my LoginView to be "~/Authenticate.aspx". Once the user is authenticated another Redirection to a members page occurs. However in my Members page it does not show that the user is logged in.
<asp:LoginStatus ID="LoginStatus1" runat="server"
LogoutAction="Redirect" BackColor="White"
Font-Underline="True" LogoutPageUrl="~/Default.aspx" />
Where am i going wrong?
when the user logs in the site will get redirected...
If the user is logging in with a username and password, then you redirect, your user is not logged in before the redirect on the LogginIn event:
Login.LoggingIn Event
The LoggingIn event is raised when a user submits login information but before the user is authenticated on the Web site. Use the LoggingIn event to set up any information that you need before authenticating a user.
Use LoggedIn instead:
Login.LoggedIn Event
The LoggedIn event is raised after the authentication provider checks the user's credentials and the authentication cookie is queued to send to the browser in the next response. Use the LoggedIn event to provide additional processing, such as accessing per-user data, after the user is authenticated.
i have a login control ,it works perfectly,,and i put login status, i get a specific problem when i specify the login image URL for my login status ,,the login control can't redirect me to the default page even when iam the right person ,it even does not enter the logging event in this case ,,when i remove the image URL every thing is okay, i wanna to use image url to clarify the status..
i note some thing:
when i enter the user name and password and click enter through keyboard i logout and the focus is on the login status control ,, when i click on the button every think is okay ,, what is the problem????
You can use the method described here:
http://forums.asp.net/t/896760.aspx
Hopefully after you define the DefaultButton to the correct Login control submit button, the ENTER key will work as expected.
You need to put the image in a folder/location that does not require authentication/authorization.