Security :: LoginView Switch To LoggedIn Template After Registering?
Mar 10, 2010
I got a loginview located on the master page hen i have a registering functionWhat I want to do is upon registration successful, I wish to directly switch to loginview template to assigned role which is member How do i do that using codebehind?
protected void Login1_LoggedIn(object sender, EventArgs e) { LoginName loginName = LoginView1.FindControl("LoginName1") as LoginName; Response.Write(loginName.ToString()); //for now I used Response.Write for testing purposes }
I'm creating a LoginView in a class file rather than at design time.
The equivalent LoginView created in a .aspx page and used the same way works fine, and User.Identity.IsAuthenticated is switching from false to true once I log in as a user so the problem must not be there.
But even once logged in, the programmatic version of this LoginView is not switching from the Anonymous template to the LoggedIn and the output is always "You are not logged in".
Anyone have ideas? thanks.
here is my code to create the loginview
private void BuildAddCommentView(HtmlTextWriter htmlTextWriter) { LoginView commentsLoginView = new LoginView();
commentsLoginView.AnonymousTemplate = new LoginViewTemplate("AnonymousTemplate"); commentsLoginView.LoggedInTemplate = new LoginViewTemplate("LoggedInTemplate");
class LoginViewTemplate:ITemplate { string _templateType;
public LoginViewTemplate(String templateType) { _templateType = templateType; }
public void InstantiateIn(Control container) {
Label label = new Label();
switch (_templateType) { case "AnonymousTemplate": label.Text = "You are not logged in."; container.Controls.Add(label); break; case "LoggedInTemplate": label.Text = "YOU ARE LOGGED IN."; container.Controls.Add(label); break; }
I use master/content page and use this code (below) for validation, if I place the PasswordRecovery outside LoginView the validation is marked up correctly, but placed back inside the LoginView the PasswordRecovery compilation error is CS0103: The name 'PasswordRecovery1' does not exist in the current context.
i'm working in my first integral website ,and i'm using the ASP.NET Login Controls but now i need to know how i can work with the user who loggedin ,i wanna visable his Data only not the all users data ,like for example the site is contain medical data for every user and when one user is logged in it will implement query to visual his Examination only.
I need to create a public string that reflects the "Distinguished Name" of the logged in user in Active Directory. I have the ADSI Edit program open and I can see the distuished names right there and they have the information I need. But I just need my program to pull it.If someone could provide code that shows how to do this I would appreciate it. I have tried the "codeproject" but I can't find it there.
I just observed something with the .net 3.5 VS2010 Login control. It seems to response.redirect is doing something I cant explain:
[Code]....
after I hit the response.redirect all that is happening is that I stay on the login page and the URL changes to http://localhost:50324/Account/Login.aspx?ReturnUrl=%2fAccount%2fAdmin%2fApproval.aspx
Why am I not properly redirected? I used server.transfer, that put me on the right page (Approval.aspx) BUT as soonas I clicked a button, I was back at Login.aspx.
My app creates a randomly-generated password when an account is created. I just tried to log in with a new account, and ASP.Net treated the following password as malicious input:
vkx&#!n#
Do we know why this particular password triggers a validation exception?
Exception information: Exception type: HttpRequestValidationException Exception message: A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$txtPassword="vkx&#!n#").
i have used an login control for the users who have not logged in and defined login verification method on the click event of the button but while excuting i do get an error
Error 1 The name 'Login1' does not exist in the current context
I am in the process of creating a forum design from scratch, as my first official asp.net application attempt.
Overview:
I would like to handle this task in the following steps:
1) Get input from the user: txtLoginEmail, txtPassword
Form has been submitted:
2) Process inputs a) cut/trim white spaces
b) encrypt password by using SHA1 hashing method located in clsLibrary
3) Check the email address given against the database
Match: Display a message saying that the username already exists.
Doesn't: Add the email address and add encrypted password into the database
Question:
In my Register.aspx.vb code-behind file, inside of the question mark lines, how exactly do I check against the database to see if that user exists in that database already? I thought perhaps storing the results in an array and then looping through it to look for matches, but that sounds inefficient. I tried this idea and after an hour I was unsuccessful. Below is my code for the class objects and pieces of code relevant to this task:
<div id="GridDiv" runat="server"> gridview would go in here.... </div> GridDiv.Visible=false;
However, because I have a Div in LoginView2 I have to find with findcontrol.
This is not work:
LoginView Div = LoginView2.FindControl("GridDiv") as LoginView; Div.Visible = false;
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[Code]....
Line 785: Line 786: Line 787: Div.Visible = false;
I have used membership provider to implement my system. The system administrator can list the users. What I want to do is, administrator should be able to sign-in as the selected user. I can sign out administrator by FormsAuthentication.Signout but how can I sign in as the selected user? Passwords are hashed so I can not retrieve the passwords.
What is the easiest way to manipulate the built in LoginView and membership handlers so that users of a website can sign up with just their email (entered twice) and a password (entered twice)? The default is asking the user for a username, the email (just once) and the password (twice). How can this be tweaked, including adjusting the in-built aspnetUser table in the database?
I was wondering if someone can direct me to a good quality tutorial on the process of registering and sending an activation link to the user's email address. I can't seem to find any useful tutorials online!
I have a website where users can login and they have different roles/privileges. I want to have it where the user's view of the webpage is determined by their role. Right now I am storing the role in the UserData property of the FormsAuthenticationTicket class (which is retrieved from a database during login). When the main page is loading, I want it to check the user's role and then only show the controls/portions of the page that are for that role. For example, if the user is not an administrator, they shouldn't be able to click on a button to delete a record. At the moment I am using labels to hide or show areas depending on the user's role. Something like this:
[Code]....
[Code]....
And here is a portion of the markup code with the Labels:
[Code]....
This works, but doesn't seem to be a very good way to handle this type of thing. Is there a cleaner, more elegant way of doing this? Something similar to the LoginView control, but which I can use for roles?
When user login into my application,the note saying that Welcome,Joe is show.But,when user try to input something into web page (such as fill in the text box),the LoginName1 that refer to "Joe" is suddenly disappear.Why this happen?
Now that some of the Security matrix has been approved and site is somewhat more functional. We are going back thru adding the loginview to the pages that need it so we can control who can adn can't see the pages and data.
To keep it simple, here is what i have setup.. Because if this setup, i cant access my controls and the page wont display either template. Now even though the aspx code below is a very stripped down version of what i have, the code behind has references to controls that dont show in my example, but they are there in my actual page. I Just removed alot of information to make the post more clear.
I have to assign default value to my asp.net controls which are residing inside the RoleGroup of Asp.net's LoginView control.
Here is a piece of my code-
[Code]....
[Code]....
But I'm getting this error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Can anyone tell me why I'm getting this error? And what is the right way of accessing those controls from code behind which are placed inside a loginView's RoleGroup?
In my MasterPage, I'm using LoginView control that looks like this:
[Code]....
In the code behind, here's what I do:
[Code]....
When I try to pull up the home page -- as an unauthenticated user -- I get "Object reference not set to an instance" error pointing to where I start building the user menu i.e. litUserMenu.Text = "<li>...
I'm using roles based authenication and am trying to populate a dropdown list from Page_Load that resides inside a LoginView control. My problem is my code behind file doesnt recognize controls inside the LoginView templates.