Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • urmila 18 posts 88 karma points
    Apr 08, 2013 @ 05:43
    urmila
    0

    FormsAuthentication.SetAuthCookie not working

    Hi all

    I am using surfacecontroller for login functionality.i am using FormsAuthentication.SetAuthCookieto remember the user credentials but it's not redirecting to to page after login automatically.I am using umbraco version 6.0

            [HttpPost]
            [ActionName("Login")]
            public ActionResult Login(LoginCommand command)
            {
               
                if (ModelState.IsValid)
                {
                    if (Membership.ValidateUser(command.Username, command.Password))
                    {
                      FormsAuthentication.SetAuthCookie(command.Username,command.RememberMe);
                      return RedirectToUmbracoPage(1112);            
                    }
                    else
                    {
                        ModelState.AddModelError("Login", "Invalid username or password");
                        return CurrentUmbracoPage();
                    }
                }
                return CurrentUmbracoPage();
            }

    This is my web.config

       <authentication mode="Forms">
    <forms name="yourAuthCookie" loginUrl="login.aspx" protection="All" path="/" defaultUrl="/account-information.aspx"/>
    </authentication>
    <authorization>
    <allow users="?"/>
    </authorization>
    <!-- Membership Provider -->
    <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
    <providers>
    <clear/>
    <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed"/>
    <add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed"/>
    </providers>
    </membership>
    <!-- added by NH to support membership providers in access layer -->
    <roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
    <providers>
    <clear/>
    <add name="UmbracoRoleProvider" type="umbraco.providers.members.UmbracoRoleProvider"/>
    </providers>
    </roleManager>
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 08, 2013 @ 11:29
    Alex Skrypnyk
    0

    Hi urmila,

    Please insert domain='.yourdomain.com"  to the forms line.

    Check what cookies do you have.

    Thanks,

    Alex

  • urmila 18 posts 88 karma points
    Apr 08, 2013 @ 11:36
    urmila
    0

    Hi alex

    what should be the domain name if i am running it on localhost?

    Thanx,

    Urmila

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 08, 2013 @ 11:37
    Alex Skrypnyk
    0

    'localhost' ))

    And when you will be on live you shoud change it to your real domain.

    Cookies are strictly bound to the domain.

    Thanks,

    Alex

  • urmila 18 posts 88 karma points
    Apr 08, 2013 @ 12:07
    urmila
    0

    Hi alex

    It's working when i hit url for /accountinformation.aspx  it directly log me in and redirect to that page but when i am running homepage then it's rediecting to login page itself after login why so?? :(

    <authentication mode="Forms">
          <forms name="yourAuthCookie" loginUrl="login.aspx" protection="All" path="/" domain="127.0.0.1" defaultUrl="/accountinformation.aspx"/>
        </authentication>

    Thanks urmila

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 08, 2013 @ 12:14
    Alex Skrypnyk
    0

    Look in your cookie, what wrong with your 'yourAuthCookie'.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 08, 2013 @ 15:46
    Alex Skrypnyk
    0

    could you watch on it ? 

     

  • urmila 18 posts 88 karma points
    Apr 09, 2013 @ 05:52
    urmila
    0

    Hi alex

    I am not able to login when i added domain to web.config because i am getting logged in member as null.When i remove it i am able to login to site and also i am getting no values in cookie.When i hit the login url i am not getting cookie either.This is the login view

    @model Luna.Umbraco.Site.Models.Command.LoginCommand
    @{
        Layout = null;
     }
     <div>
      <link href="@Url.Content("~/css/style.css")" rel="stylesheet" type="text/css" />
     </div>                       
     <style type="text/css">
         .errorMsg
         {
             color:Red;
         }
     </style>
       @{  
         
      using (Umbraco.Web.HtmlHelperRenderExtensions.BeginUmbracoForm(Html,"Login","LoginSurface"))
      {
                <div>
                     <label class="contentLeftlabel">User name:</label>&nbsp;
                     @Html.EditorFor(Model => Model.Username)
                     <span class="errorMsg">@Html.ValidationMessageFor(Model => Model.Username, "*")</span>
                     <br /><br />
                </div>
                <div>
                    <label class="contentLeftlabel">Password:</label>&nbsp;
                     @Html.EditorFor(Model => Model.Password)
                     <span class="errorMsg">@Html.ValidationMessageFor(a => a.Password, "*")</span>
                    <br /><br />
                </div>
                <div>
                    <label class="floatL padding">Remember Password </label>&nbsp;
                    @Html.CheckBoxFor(Model => Model.RememberMe)
                    <br /><br />
               </div>
               <div>
                    <input type="submit" id="submit" name="submit" value="sign in now" class="btn floatR margin-top"/>
               </div>
               <div style="color:Red">
                    @Html.ValidationSummary()
                   
               </div>
     
       }
          }


    And this the template to which i am redirecting after login

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Luna.Umbraco.Site.Models.Command;
    @using umbraco.cms.businesslogic.member;
    @{
        Layout = null;
    }

    @{
        Member member = umbraco.cms.businesslogic.member.Member.GetCurrentMember();
     }
     <p>This page is under construction</p>
        <p>Logged in:@member.LoginName</p>
        <p>@Html.ActionLink("Log out", "Logout", "LoginSurface")</p>

    Thanks Urmila

  • urmila 18 posts 88 karma points
    Apr 18, 2013 @ 10:21
    urmila
    100

    Hi all

    I finally found the solution

      if(Request.IsAuthenticated)
          {
              Response.Redirect("/accountinformation.aspx");
          }

    Just need to add this on my login view.

    Thanks urmila

Please Sign in or register to post replies

Write your reply to:

Draft