2016-11-19 67 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。 –

回答