Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is code in Login view :-
HTML
@model White.Whale.Models.AuthLogin

@{
    @ViewBag.Title = "Login";
    Layout = null;
}

<div class="row">
    <div class="col-md-8">
        <section id="loginForm">
            @using (Html.BeginForm("Login", "Auth", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
            {
                @Html.AntiForgeryToken()
                <h4>Use a local account to log in.</h4>
                <hr />
                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group">
                    @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <div class="checkbox">
                            @Html.LabelFor(m => m.Password)
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Log in" class="btn btn-default" />
                    </div>
                    <div>
                        @ViewBag.Message
                    </div>
                </div>
            }
        </section>
      </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


and i change authentication in web.config but i have the same error:-
C#
<authentication mode="Forms">
     <forms loginUrl="~/Auth/login"></forms>
   </authentication>


What I have tried:

i tried change authentication in web.config
Posted
Comments
John C Rayan 23-May-16 7:35am    
can you provide us with your default route entry from Route config.
MahmoudOmar 23-May-16 7:41am    
i create database in project and i add entity model ,
this is code that i change it in Authlogin Class,
public partial class AuthLogin
{
public int UserId { get; set; }

[Required(ErrorMessage = "Please enter your name")]
[Display(Name = "User Name")]
public string UserName { get; set; }

[Required(ErrorMessage = "Please enter your password")]
[Display(Name = "Password")]
[DataType(DataType.Password)]
public string Password { get; set; }
public bool CheckUser(string Username, string Password)
{
bool flag = false;

string conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from AuthLogin where Username = '" + Username + "' and Password = '" + Password + "'", con);
flag = Convert.ToBoolean(cmd.ExecuteScalar());
return flag;
}
}

}

and code in controoler:-
public ActionResult Login()
{
return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(AuthLogin login)
{
if(ModelState.IsValid)
{
if(login.CheckUser(login.UserName,login.Password))
{
return View("Notification", login);
}
else
{
ViewBag.Message = "Invalid Username or Password";
return View();
}
}
else
{
return View();
}
}
John C Rayan 23-May-16 8:55am    
Can you post your RouteConfig.cs under application_start folder.
MahmoudOmar 23-May-16 9:10am    
this is RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Auth", action = "Login", id = UrlParameter.Optional }
);
}
John C Rayan 23-May-16 9:27am    
It seems to be fine. My gut feeling is that you are using Visual studio and if that's the case can you change the start page in web settings to the proper route , rather than the URL.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900