Having a form in logonusercontrol.ascx

Last post 07-08-2009 4:23 AM by Tomorrow. 1 replies.

Sort Posts:

  • Having a form in logonusercontrol.ascx

    07-04-2009, 10:30 PM
    • Member
      point Member
    • uniqueumang
    • Member since 07-05-2009, 1:55 AM
    • Posts 3

    Greeting everyone,

    I have recently started working with asp.net , and deceided to jump to asp.net mvc. I am familiar with MVC and I used it to make application alot more robust.

    I took time to get familiarise with MVC , and decided to make changes to the system to fit my needs. I donot prefer to have an extra click to login, so i decided to have loginform in LogOnUserControl.ascx . Please note that all the code I am using so far is provided by MVC application itself. I have just make teeny tiny adjustment. Following is my LogOnUserControl.ascx

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <%
        if (Request.IsAuthenticated)
        {
    %>
    Welcome <b>
        <%= Html.Encode(Page.User.Identity.Name) %></b>! [
    <%= Html.ActionLink("Log Off", "LogOff", "Account") %>
    ]
    <%
        }
        else
        {
    %>
    <%= Html.ValidationSummary("Login was unsuccessful. Please correct the errors and try again.") %>
    <% using (Html.BeginForm("LogOn", "Account"))
       { %>
    <div id="loginForm">
        <fieldset>
            <legend>Login</legend>
            <p>
                <label for="username">
                    Username:</label>
                <%= Html.TextBox("username")%>
                <%= Html.ValidationMessage("username")%>
            </p>
            <p>
                <label for="password">
                    Password:</label>
                <%= Html.Password("password")%>
                <%= Html.ValidationMessage("password")%>
            </p>
            <p>
                <%= Html.CheckBox("rememberMe")%>
                <label class="inline" for="rememberMe">
                    Remember me?</label>
            </p>
            <p>
                <input type="submit" value="Log On" />
            </p>
        </fieldset>
        
    </div>
    <%
       } 
            %>
    <div id="registerHere">
        <fieldset>
            <legend>Register</legend>
            <p>
                Please enter your username and password.
                <%= Html.ActionLink("Register","Register","Account") %>
                if you don't have an account.
            </p>
        </fieldset>
    </div>
    <%
        
        }
    %>
    

    Now the problem is that is the I can't login from this form. I get following error:

    Server Error in '/' Application. Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.


    I am not sure why I am getting error regarding it. I tried googling but solution provided didn't help much. Solution including removing form tags from site.master.

    Your help is alot appreciated.


    Thanks


    With Regards

    -Umang

  • Re: Having a form in logonusercontrol.ascx

    07-08-2009, 4:23 AM
    Answer
    • Contributor
      3,290 point Contributor
    • Tomorrow
    • Member since 12-10-2008, 1:39 AM
    • Posts 343

     

    uniqueumang:
    Validation of viewstate MAC failed

    <pages enableEventValidation="false" viewStateEncryptionMode ="Never" />

     http://blogs.msdn.com/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx

    http://aspadvice.com/blogs/joteke/archive/2006/02/02/15011.aspx

     

     

Page 1 of 1 (2 items)