2016-11-19 70 views
0

我对编程c#和asp.net有点新,我只是想为我的android应用程序构建一个休息api来登录和注册。但我面临登录(登录)的问题。
的问题是,我只写了这以下代码:
描述:用于JSON的HTTP 404返回

namespace CPanel.Controllers 
{ 
    public class DashboardController : Controller 
    { 
     // GET: Dashboard 
     public ActionResult CreateUser() 
     { 
      return View(); 
     } 

     [HttpPost] 
     public ActionResult CreateUser(string username,string password) 
     { 
      CPanel.Models.CPanelEntities1 db = new Models.CPanelEntities1(); 
      db.USP_AddUSer(username, password); 
      return View(); 
     } 


     [HttpPost] 
     public ActionResult login(string username,string password) 
     { 
      CPanel.Models.CPanelEntities1 db = new Models.CPanelEntities1(); 
      try 
      { 
       var user = db.USP_Authenticate(username, password).First(); 
       return Json(new { UserId = user.UserId,Username=user.Username,IsAdmin=user.IsAdmin,Message="ok"}); 
      }catch(Exception) 
      { 
       return Json(new { message = "error" }); 
      } 
     } 
    } 
} 

第一部分(CREATEUSER)很好地工作。但第二部分(登录)仅适用于“Postman”Chrome应用程序。
我张贴的 “邮差” 的请求 -

localhost/dashboard/login?username=php&password=php

,我看到一个JSON:

{ "UserId": 29, "Username": "php", "IsAdmin": false, "Message": "ok" }

在本地主机和wwwroot文件(IIS)那里没有机会和我面对这个错误:

Server Error in '/' Application.

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: /dashboard/login

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1586.0

+0

你能说清楚你是什么意思_“在localhost和wwwroot(iis)没有机会”_?您是否尝试从网络浏览器访问网址,但无法使用? –

+0

那么他找不到你指定的URL。您确定要在仪表板之前使用斜线吗?你是否开始在根文件夹? – Hespen

+0

我认为url没有问题,因为我通过“邮差”中的网址,正如我所说的,并得到我想要的json。 –

回答