Copied to clipboard

Flag this post as spam?

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


  • Manasa 41 posts 161 karma points
    Dec 01, 2016 @ 17:02
    Manasa
    0

    refresh the umbraco website after member login

    Hi, I want my website to auto refresh after member login, i am restricting some pages in my website, and they are getting visible after login ,( but only after manually refreshing the website. )I don't want user to refresh the website. is there any way to auto refresh my website in code behind, it would be great if someone help me out ,thank you in advance.

  • raibow 10 posts 80 karma points
    Dec 01, 2016 @ 18:07
    raibow
    0

    Could you clarify, do you mean Umbraco backoffice member or website user?

    How do you handle the login form? It would be nice to see some your code snippets...

  • Manasa 41 posts 161 karma points
    Dec 01, 2016 @ 18:13
    Manasa
    0

    sure,I want to refresh/reload current page after user login

    here is my snippet, it is working fine , the only thing is i need to refresh the page.

    <fieldset>
    
                    @Html.ValidationSummary("loginModel", true)
                    <label>User Name</label>
                    @Html.TextBoxFor(m => loginModel.Username, new { placeholder = "User Name" , @class = "form-control"  })
                    @Html.ValidationMessageFor(m => loginModel.Username)
                    <br/>
                     <label>Password</label>
                     @Html.PasswordFor(m => loginModel.Password,new {placeholder="Password" , @class = "form-control" })
                     @Html.ValidationMessageFor(m => loginModel.Password)
                    <br/>
                    <div class="form-group">    
                        <button class="btn btn-primary btn-block" >Sign in</button>
    
                    </div>
    
    </fieldset> 
    
  • raibow 10 posts 80 karma points
    Dec 01, 2016 @ 18:41
    raibow
    0

    So how do you submit above login functionality? I guess you use some javascript logic to handle that...

    I think it would be much better to use some Umbraco form with Surface controller. Then the page reload would be handled automatically with POST request...

    The View:

    @{
       var loginModel = new CustomLoginModel();
    }
    
    @using (Html.BeginUmbracoForm<LoginController>("HandleLogin", null, new { @class = "login-form" }))  
    {
                @Html.LabelFor(m => loginModel.Username)
                @Html.ValidationMessageFor(m => loginModel.Username, null, new {@class = "validation-message"})
                @Html.TextBoxFor(m => loginModel.Username, new {@class = "form-control"})
    
                @Html.LabelFor(m => loginModel.Password)
                @Html.ValidationMessageFor(m => loginModel.Password, null, new {@class = "validation-message"})
                @Html.PasswordFor(m => loginModel.Password, new {@class = "form-control"})
    
                <button type="submit" class="btn btn-primary">Sign in</button> 
    }
    

    The controller:

    public class LoginController : SurfaceController
    {
        [HttpPost]
        public ActionResult HandleLogin([Bind(Prefix = "loginModel")]CustomLoginModel model)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.Username, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Username, true);
                    return RedirectToCurrentUmbracoPage();
                }
            }
            TempData["LoginFailed"] = true;
            return CurrentUmbracoPage();
        }
    }
    
  • Manasa 41 posts 161 karma points
    Dec 01, 2016 @ 20:17
    Manasa
    0

    Thank you raibow, but where should i put the controller code , I am driving my code from umbraco back office , not from visual studio MVC application.

  • raibow 10 posts 80 karma points
    Dec 01, 2016 @ 20:38
    raibow
    0

    In that case you basically can't use it. That's because before you could use it you have to compile it.

    You can use then the default Umbraco login controller. Please do as described below:

        @{
            var loginModel = new LoginModel();
            loginModel.RedirectUrl = "/your-url"; //redirect to the specific url after successful sign in
         }
    
    @using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
    {
        <fieldset>
            <legend>Login</legend>
    
            @Html.ValidationSummary("loginModel", true)
    
            @Html.LabelFor(m => loginModel.Username)
            @Html.TextBoxFor(m => loginModel.Username)
            @Html.ValidationMessageFor(m => loginModel.Username)
            <br />
    
            @Html.LabelFor(m => loginModel.Password)
            @Html.PasswordFor(m => loginModel.Password)
            @Html.ValidationMessageFor(m => loginModel.Password)
            <br />
    
            @Html.HiddenFor(m => loginModel.RedirectUrl)
            <button>Login</button>
        </fieldset>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft