【发布时间】:2019-02-08 00:24:53
【问题描述】:
我想要的是,将电子邮件 ID 作为请求对象并检查该电子邮件 ID 是否存在于数据库中的 API。如果电子邮件 ID 存在,Api 将返回 true 作为响应,否则返回 false。
我所做的是:-
我已经为 Emaiid 定义了如下路线之一:-
config.Routes.MapHttpRoute(
name: "ApiEmailId",
routeTemplate: "api/{controller}/{action}/{email}",
defaults: null,
constraints: new { name = @"^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))+$" }
);
我也试过这个:-
config.Routes.MapHttpRoute(
name: "ApiEmailId",
routeTemplate: "api/{controller}/{action}/{email}",
defaults: null,
constraints: new { name = @"^[a-z]+$" }
);
我还写了如下的actionresult:-
public IHttpActionResult GetEmailID(string email)
{
//New action condition
//To get employee records
var tblCountryName = from a in db.tblEmployeeRecords
where a.userName == email
select a;
if (tblCountryName == null)
{
return NotFound();
}
return Ok(tblCountryName);
}
当我使用 Postman 访问 API 时:-
网址:-
GET http://localhost/api/tblEmployeeRecords/GetEmailID/firstname.lastName@companyname.onmicrosoft.com
错误,我得到了:-
<h3>HTTP Error 404.0 - Not Found</h3>
<h4>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</h4>
</div>
<div class="content-container">
<fieldset>
<h4>Most likely causes:</h4>
<ul>
<li>The directory or file specified does not exist on the Web server.</li>
<li>The URL contains a typographical error.</li>
<li>A custom filter or module, such as URLScan, restricts access to the file.</li>
</ul>
</fieldset>
请帮帮我,我哪里错了,有什么解决办法?
【问题讨论】:
-
控制器名称是什么?
-
你的控制器真的叫
tblEmployeeRecords吗? -
@ChetanRanpariya tblEmployeeRecords 是控制器名称
-
@BrendanGreenYes
标签: asp.net-mvc entity-framework asp.net-web-api asp.net-web-api-routing