When I create a user using membership in asp.net, after successfully create user it get automatically login to the system. But I don't want to login immediately. Can someone help me?
Set LoginCreatedUser property to false.
For example,
protected void Page_Load(object sender, EventArgs e)
{
// Replace createUserWizard1 with ID of your CreateUserWizard control.
createUserWizard1.LoginCreatedUser = false;
}
Related
I have a page. There are some session variables those are used in a specified page only. How to clear those session variables when user left the page.
When user left the page using the menu/URL.
I have tried with
protected void Page_Unload(object sender, EventArgs e)
{
Session["Rules"] = null;
Session.Remove("Rules");
}
But it is now working :(
Please suggest.
i am using an ASP control Login and i want to redirect the user logged in depending on its role. But it seems like The User take the previous value of the last logged in user. seems problem of refresh the current user or something like this
Code of my webform1.aspx.cs:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
TextBox1.Text = Context.User.Identity.Name.ToString();
if (Context.User.IsInRole("admin"))
{
Response.Redirect("~/admin.aspx");
}
else if (User.IsInRole("user"))
{
Response.Redirect("~/user.aspx");
}
}
Inside LoggedIn event of Login control, principal object hasn't been attached to the current HttpContext yet.
Therefore, you cannot use Context.User inside LoggedIn event.
protected void Login1_LoggedIn(object sender, EventArgs e)
{
var roles = Roles.GetRolesForUser(Login1.Username);
if (roles.Contains("admin"))
{
Response.Redirect("~/admin.aspx");
}
else if (User.IsInRole("user"))
{
Response.Redirect("~/user.aspx");
}
}
Can I add an event handler to a session value in asp.net with c#?
I'm planning to update the database when user logs in and logs out and I control login and logout with session values, but the session may end without a user click, like timeout, so I'd like to add an event handler to "isloggedin" session value.
you need to handle this in global.asax.
protected void Session_Start(Object sender, EventArgs e)
{
//your code
}
protected void Session_End(Object sender, EventArgs e)
{
//your code
}
You can implement the Session_End method in the global.asax. There, you will retrieve what information you need from the session, and do what you need to (like setting logout flag in database for the user):
Here's an example of what I do, though you can tailor it to your needs:
void Session_End(object sender, EventArgs e)
{
SessionPlayerContext context = (SessionPlayerContext)this.Session[Constants.SessionKeys.UserContext];
if (context != null)
PlayerManager.SetPlayerOnlineStatus(context.PlayerID, false);
}
The key is that I'm getting the user object that I previously stored in the session (when user logged in), and if it exists, I then flag the user as being logged out in the database (via PlayerManager)
Not only should you check it in the Session_End, but you also should check it wherever user would physically log out.
As for setting the user as being logged in, you will handle that when user physically logs in.
I'm programming an MVC3 application. Now I hava to call a script if the users session expire.
Is there something like a event on-session-expire, that get fired when the user session expired?
Thanks a lot!
In your Global.asax
you can create a
protected void Session_End(object sender, EventArgs e) { }
method which should be called when a session ends.
I want pass values between web user controls without writing any code to the main page which user controls are put on. I do something like that but after doing that I need to click double to pass the value.
The example of what I've done :
Department User Control (Code-Behind)
protected void Page_Load(object sender, EventArgs e)
{
int productId = ProductUserControl.selectedProductId;
... doing some bind work with productId
}
Product User Control
public static int selectedProductId;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lvDepartments_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "selectDepartment")
{
selectedProductId = int.Parse(e.CommandArgument);
}
}
Thanks in advance...
In your Department User Control you are trying to get the value of selectedProductId before it is set in the Product User Control. That's why you don't get the value you expect until you postback twice.
You'll need to get it after the Product User Control sets it in the ItemCommand event. Perhaps placing the Department User Control code in the Page_LoadCompleted... though I'm not sure if that will work either.
Another way to do it is to have Product User Control set a public property in Department User Control instead of having Department User Control try to read a property in Product User Control.
The issue seems to be a Page Lifecycle issue.
http://www.robincurry.org/blog/content/binary/o_aspNet_Page_LifeCycle.jpg
I'm sure there's a better way than that as well.
Try using delegates to achieve this more cleanly, example here