Mvc登录URL错误 [英] Mvc Login Url Error

查看:162
本文介绍了Mvc登录URL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法找到资源。

描述:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。



请求的网址:/首页/登录





我的代码: = b / b

  public  ActionResult Login()
{
返回 查看();
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult登录(用户 u)
{
//此操作 for handle post(login)
if (ModelState.IsValid)//此 检查有效性
{
使用(ProjectManagementEntities dc = new ProjectManagementEntities() )
{
var v = dc.UserMasters。其中(a => a.UserName.Equals(u.UserName)&& ; a.UserPassword.Equals(u.UserPassword))。FirstOrDefault();
if (v!= null
{
Session [ LogedUserID] = v.ID.ToString();
会话[ LogedUserFullname] = v.UserName.ToString();
return RedirectToAction( 创建);
}
}
}
返回 查看( U);
}

解决方案

这意味着URL无效,因为您可能没有在Route.config.cs中注册

看起来像这样: -

  public   static   void  RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute( {resource} .axd / {* pathInfo});

routes.MapRoute(
name: 默认
url: {controller} / {action} / {id}
默认值: new {controller = Home,action = 登录,id = UrlParameter.Optional} // 在您的情况下,如果Login是默认URL。
);
}



请查看此信息并回复您的疑问。

谢谢


< blockquote>嘿检查...你没有从解决方案中删除任何与LOGIN相关的视图或母版页或部分页面?


The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Home/Login


My Code:=

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

       [HttpPost]
       [ValidateAntiForgeryToken]
       public ActionResult Login(User u)
       {
           // this action is for handle post (login)
           if (ModelState.IsValid) // this is check validity
           {
               using (ProjectManagementEntities dc = new ProjectManagementEntities())
               {
                   var v = dc.UserMasters.Where(a => a.UserName.Equals(u.UserName) && a.UserPassword.Equals(u.UserPassword)).FirstOrDefault();
                   if (v != null)
                   {
                       Session["LogedUserID"] = v.ID.ToString();
                       Session["LogedUserFullname"] = v.UserName.ToString();
                       return RedirectToAction("Create");
                   }
               }
           }
           return View(u);
       }

解决方案

This means the URL is not valid as you may not have registered in the Route.config.cs
Which looks like:-

public static void RegisterRoutes(RouteCollection routes)
       {
           routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

           routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional } //As in your case if the Login is default URL.
           );
       }


Please check with this and post back your queries if any.
Thanks


hey check ... u did not delete any views or master pages or partial pages related to LOGIN from your solution ?


这篇关于Mvc登录URL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆