Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 公共类HomeController:控制器 { 公共行动结果索引() { 返回视图(); } [HttpGet] 公共操作结果登录() { return View();//用于登录表单 } [HttpPost] 公共无效登录(字符串用户名,…) { //首_Javascript_Sql Server_Asp.net Mvc - Fatal编程技术网

Javascript 公共类HomeController:控制器 { 公共行动结果索引() { 返回视图(); } [HttpGet] 公共操作结果登录() { return View();//用于登录表单 } [HttpPost] 公共无效登录(字符串用户名,…) { //首

Javascript 公共类HomeController:控制器 { 公共行动结果索引() { 返回视图(); } [HttpGet] 公共操作结果登录() { return View();//用于登录表单 } [HttpPost] 公共无效登录(字符串用户名,…) { //首,javascript,sql-server,asp.net-mvc,Javascript,Sql Server,Asp.net Mvc,公共类HomeController:控制器 { 公共行动结果索引() { 返回视图(); } [HttpGet] 公共操作结果登录() { return View();//用于登录表单 } [HttpPost] 公共无效登录(字符串用户名,…) { //首先在此处验证您的登录 FormsAuthentication.SetAuthCookie(用户名,true); } } 这是哪个版本的.net。net core或.net framework?mvc 5、.net corewell mvc 5不

公共类HomeController:控制器 { 公共行动结果索引() { 返回视图(); } [HttpGet] 公共操作结果登录() { return View();//用于登录表单 } [HttpPost] 公共无效登录(字符串用户名,…) { //首先在此处验证您的登录 FormsAuthentication.SetAuthCookie(用户名,true); } }

这是哪个版本的.net。net core或.net framework?mvc 5、.net corewell mvc 5不在.net core之下。net核心有MVC6,MVC5在.net下framework@NevilleNazerane:您的项目中是否有
web.config
文件?这是哪个版本的.net。net core或.net framework?mvc 5、.net corewell mvc 5不在.net core之下。net核心有MVC6,MVC5在.net下framework@NevilleNazerane:您的项目中是否有
web.config
文件?能否请您进一步解释?能否请您进一步解释?我尝试了您的建议,但我想说的是,我没有使用EF,我没有帐户控制器,我的登录操作是在HomeController中,但我尝试了你建议的,另外,项目中有两个web配置,我应该修改其中一个。这不使用EF。帐户控制器只是一个例子。您也可以在HomeController中执行所有操作。但是您的登录操作用于提交您的登录信息。你需要在任何地方做另一个动作。返回登录html表单的视图。您需要修改主文件夹中的web.config,而不是视图文件夹中的web.config。我有一个登录操作返回另一个视图。能在代码中看到我的更新吗是的,我刚刚更新了代码。也不要让你发布的动作返回另一个视图。如果表单发布到某个操作,请使用
重定向
函数之一,例如
重定向到操作
,重定向到另一个返回视图的操作。主要替换我刚才提到的行。这是主要问题。然后,代替
会话[“currentUser”]!=null
,使用
用户。已验证
。我尝试了您建议的内容,但我想说的是,我没有使用EF,我没有帐户控制器,我的登录操作在HomeController中,但我尝试了您建议的内容,另一件事,项目中有两个web配置,我应该修改其中一个。这不使用EF。帐户控制器只是一个例子。您也可以在HomeController中执行所有操作。但是您的登录操作用于提交您的登录信息。你需要在任何地方做另一个动作。返回登录html表单的视图。您需要修改主文件夹中的web.config,而不是视图文件夹中的web.config。我有一个登录操作返回另一个视图。能在代码中看到我的更新吗是的,我刚刚更新了代码。也不要让你发布的动作返回另一个视图。如果表单发布到某个操作,请使用
重定向
函数之一,例如
重定向到操作
,重定向到另一个返回视图的操作。主要替换我刚才提到的行。这是主要问题。然后,代替
会话[“currentUser”]!=空
,使用
User.IsAuthenticated
 @if (Session["currentUser"] != null)
 {
    <script type='text/javascript'>
$(document).ready(function(){
    $("#login").hide();
});
    </script>
 }
        <div class="login" id="login">
            @*@RenderPage("~/Views/Home/Login.cshtml")*@
            <link href="~/Content/toastr.css" rel="stylesheet" />
            <div class="main-w3l">
                <div class="w3layouts-main" style="background-image:url('/template/web/images/bg3.jpg'); margin-top:50px;">
                    <h2>Login Now</h2>


                    @using (Html.BeginForm("Login", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
                    {


                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)

                        <input value="E-MAIL" name="Email" type="email" required="" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'E-Mail';}" />
                        <input value="PASSWORD" name="Password" type="password" required="" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'password';}" />
                        <span><input type="checkbox" />Remember Me</span>
                        <h6><a href="#">Forgot Password?</a></h6>
                        <div class="clear"></div>
                        <input type="submit" value="login" name="login">

                    }

                    <p>Don't Have an Account ?<a href="#" onclick="@("window.location.href='" + @Url.Action("Create", "Client") + "'") ;">Register Now</a></p>
                </div>
            </div>
  public ActionResult Login()
        {
            return View();
        }

    database_Access_layer.db dblayer = new database_Access_layer.db();


    [HttpPost]
    public ActionResult Login(FormCollection fc, string LastName, string Email)
    {

        int res = dblayer.Admin_Login(fc["Email"], fc["Password"]);
        if (res == 1)
        {
            Session["currentUser"] = Email;
            string z = Email;
            connection();
            con.Open();
            SqlCommand command = new SqlCommand("select Email from Client", con);

            List<string> result = new List<string>();
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                    result.Add(reader.GetString(0));
                con.Close();
            }
            foreach (string x in result)
            {
                if (x == z)
                {

                    SqlCommand command2 = new SqlCommand($"select LastName from Client WHERE Email= '{x}' ", con);
                    con.Open();
                    string y = command2.ExecuteScalar().ToString();
                    con.Close();
                    Session["currentUser"] = y;

                }
            }

            return RedirectToAction("Profil", "Client");
            Session.RemoveAll();


        }
        else {

            TempData["msg"] = " Email or Password is wrong !";
            return RedirectToAction("Index", "Home");

        }

    }
FormsAuthentication.SetAuthCookie(UserName, remember);
<authentication mode="Forms">

</authentication>
<authentication mode="Forms">
    <forms loginUrl="~/Home/Login" timeout="2880" />
</authentication>
[Authorize]
public ActionResult Index(){
    return View()
}
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }

    [HttpGet]
    public ActionResult Login()
    {
        return View();  // for the login form
    }

    [HttpPost]
    public void Login(string UserName, .... <other fields>)
    {
        // validate your login first here
        FormsAuthentication.SetAuthCookie(UserName, true);
    }

}