WebSecurity.IsAuthenticated

Discussion in 'Visual Studio' started by SkierBob, Oct 30, 2013.

  1. if (WebSecurity.Login(email, password, rememberMe))
    LoginOk = WebSecurity.Login(email, password, rememberMe);
    Both of these return True
    but (WebSecurity.IsAuthenticated) never get set True &
    WebSecurity.CurrentUserName never gets set
    One of the ASP. NET Forum replies suggested that my hosting server might not
    support Sql Server Ce is that relevant if so how?
    I have been searching for an answer for some time.. any ideas . I am new to this so please be specific.
     
  2. FrankC

    FrankC DiscountASP.NET Staff

    Did you set up or upload your membership database in the SQL server?
     
  3. Thanks for your response
    Yes, the membership database is loaded and the registration page works .. Using the SQL management tool I can see new members being added to the UserProfiles and Membership tables.
    This piece of code works see previous thread for more of the code it redirects you to the LoggedIn Page -- See page
    http://bobsplaceonthelake.com/myapp2/

    LoginOk = WebSecurity.Login(email, password, rememberMe);

    if (LoginOk)
    {
    Response.Redirect("~/Account/LoggedIn");
    return;
    }
     
  4. SQLCE is indeed supported. Im assuming you have configured things correctly for now as you mention you can see data in the database. Also, some of the websecurity class methods are behaving as expected.
    1 – Can you verify that the user is confirmed? You can either look in the database or use WebSecurity.IsConfirmed to determine this.
    2 – If the value of WebSecurity.Login(email, password, rememberMe) returns true and you next try to obtain WebSecurity.CurrentUserName what happens? Do you get an error message? If so what is the message?
    3 – Can you provide links to the other threads you reference in this post?
     
  5. Thanks for your response I will appreciate any help you can give I am stumped
    Here are some of the articles I have looked at , there were quite a few more but these are the most relevant .
    http://forums.asp.net/p/1946857/5548710.aspx?WebSecurity IsAuthenticated not working
    http://stackoverflow.com/search?q=WebSecurity.IsAuthenticated
    http://stackoverflow.com/questions/...eb-security-isauthenticated/14706859#14706859

    Here are my sites http://bobsplaceonthelake.com/myapp2 http://bobsplaceonthelake.com/myapp
    Here is the Log in code
    // Attempt to log in using provided credentials
    if (WebSecurity.Login(email, password, rememberMe)) {

    // Added this code for testing... it works

    LoginOk = WebSecurity.Login(email, password, rememberMe);

    if (LoginOk)
    {
    Response.Redirect("~/Account/LoggedIn");
    return;
    }


    Context.RedirectLocal(returnUrl);
    return;
    } else {
    ModelState.AddFormError("The user name or password provided is incorrect.");
    }
    Here is the LoggedIn Page code
    @{
    Page.Title = "Logged In";
    var returnUrl = Request.QueryString["ReturnUrl"];

    string msg = "";


    <span>
    Welcome To Bob's Place on the Lake LoggedIn page WebSecurity.CurrentUserName should be here -> <strong>@WebSecurity.CurrentUserName</strong> <-!
    <ahref="~/Account/Logout" title="Logout">Logout</a>
    </span>


    }
     
  6. Can you try what is outlined in the first two questions posted by Raymond?
     
  7. Thanks for responding..
    I did try Raymond recommended I think. look at the code in my response to him..then look at my site
    http://bobsplaceonthelake.com/myapp2
    And have watched the database and it looks ok. Users can register they show up in the database and when they come back it will recognize that they are registered
    Try the site see what you think.... I am stumped I need all the help I can get.
     
  8. Hey Bob,

    I cant actually test the stuff on your account. If we are assuming everything is setup right and we want to troubleshoot, we want to check a couple things. First, there is a IsConfirmed field in the database. Its essentially the flag that marks the user as confirmed after they sign up. For example, you signup to a service but you have to click a link in an email after to confirm your registration.

    Your LoginOk = WebSecurity.Login(email, password, rememberMe); tells us that the username is in the database, however you said:

    (WebSecurity.IsAuthenticated) never get set True &
    WebSecurity.CurrentUserName never gets set

    Im not sure, but for the user to be officially authenticated, I believe their login must be confirmed first then once logged in, they are officially authenticated. We should check this step as mentioned in Raymond's post.

    Next, we want to know what you mean by "WebSecurity.CurrentUserName never gets set". Is the value null? Are you getting an exception? Is it a blank string? What about the .CurrentUserId? Do you get a value or a -1?

    Take a look at the following and see if these help:
    http://www.asp.net/web-pages/tutorials/security/16-adding-security-and-membership

    http://mikepope.com/blog/DisplayBlog.aspx?permalink=2240
     
  9. I really appreciate your help.
    I am working way through the two tutorials at the links you gave me. Here is what I have done also:
    Here is the are my databases I see that he IsConfirmed is True

    Here are some testing code that I have tried.
    p>Lake LoggedIn page </p>
    <p>WebSecurity.CurrentUserName should be here -> <strong>@WebSecurity.CurrentUserName</strong> <-! </p>
    <p> WebSecurity.IsAuthenticated should be here -> <strong>@WebSecurity.IsAuthenticated </strong><-!</p>
    <p> WebSecurity.CurrentUserId should be here -> <strong>@WebSecurity.CurrentUserId </strong><-!</p>

    @if (!userName.IsEmpty()) {
    <p> WebSecurity.IsConfirmed(userName) should be here -> <strong>@WebSecurity.IsConfirmed(userName) </strong><-!</p>
    }else{
    <p> WebSecurity.IsConfirmed(userName) should be here -> <-!</p>
    }
    Here is the result on localhost
    [​IMG]
    Here Is the result when I publish it
    [​IMG]
     

    Attached Files:

    Last edited: Nov 5, 2013
  10. Hi Mickey
    Had to take a break from this it gets to me after a while...
    Do you have any more ideas.
    I worked though both the tutorials that you gave but still cannot see what is wrong with my site.
     

Share This Page