ASP.NET Core Routing适用于VS IIS Express,但不适用于IIS 10 [英] ASP.NET Core Routing works in VS IIS Express but not in IIS 10
问题描述
我正在开发ASP.NET Core Web API。在这里我有一种情况,比如我必须使用多个 get
函数从SQL Server DB获取数据。所以,为此,我正在做自定义属性路由。以下是我的代码
[Route(api / [controller])]
公共类MeController:Controller
{
private readonly ITechRepository _tech;
private readonly IPageOptions _page;
public MeController(ITechRepository tech,IPageOptions页面)
{
_tech = tech;
_page = page;
}
[路线(getTech)]
公共IEnumerable< TechStack> Get()
{
return _tech.getAll();
}
[Route(getOptions)]
public IEnumerable< PageControl> getOptions()
{
return _page.getOptions();
}
// GET api / values / 5
[HttpGet({id})]
public int Get(int id)
{
返回id;
}
}
以上路由在VS IIS Express中运行良好这是该网址
http:// localhost:51889 / api / me / gettech
但是当我在IIS 10中发布此API时, getTech
和 getOptions
无法生成 404
错误以及 [HttpGet({id})]
正在两者中工作。
任何人都可以帮忙......
最后我解决了问题。
问题在于SQL服务器的登录。我在我自己的名为 aspNetCore 的应用程序池中的IIS 10中配置了我的应用程序。它的配置是
.Net CLR版本:没有托管代码
托管流水线模式: Integerated
身份: ApplicationPoolIdentity
身份导致问题。
当我将此URL称为
在那里,我提供了用户名,已在我的用户组和SQL Server中找到的帐户的密码。我为我的数据库提供了 dbowner
此帐户的权利。
但我仍然不知道为什么它会返回404错误。
无论如何,这个问题是现在修复。
快乐编码:)
I am developing ASP.NET Core web API. here I have a situation like I have to use multiple get
functions which get data from SQL server DB. So for that, I'm doing custom attribute routes. below are my codes
[Route("api/[controller]")]
public class MeController : Controller
{
private readonly ITechRepository _tech;
private readonly IPageOptions _page;
public MeController(ITechRepository tech,IPageOptions page)
{
_tech = tech;
_page = page;
}
[Route("getTech")]
public IEnumerable<TechStack> Get()
{
return _tech.getAll();
}
[Route("getOptions")]
public IEnumerable<PageControl> getOptions()
{
return _page.getOptions();
}
//GET api/values/5
[HttpGet("{id}")]
public int Get(int id)
{
return id;
}
}
The above routes are works well in VS IIS Express and this is that URL
http://localhost:51889/api/me/gettech
But when i publish this API in IIS 10. The getTech
and getOptions
were not working it producing 404
error and also [HttpGet("{id}")]
is working in both.
Can anybody help on this...
Finally I got the issue fixed.
The problem was in the login of SQL server. I configured my application in IIS 10 in the my own Application Pool named aspNetCore. Its configurations are
.Net CLR version : No managed code
Managed pipelined mode : Integerated
Identity : ApplicationPoolIdentity
Identity cause the issue.
When i call this URL http://localhost:51889/api/me/gettech the IIS try to login into the SQL Server with the Login Id of IIS Apppool / aspNetCore. Then ended up with the following error
Login failed for user 'IIS APPPOOL\AspNetCore'. Reason: Could not find a login matching the name provided. [CLIENT: ]
I captured the above issue in Event Log with Event ID : 18456
For this I have to create the Local User and group for this identity. Unfortunately i can't able do this because i'm using Windows 10 Home edition. which does not allow me to do this.
what i did is create the Custom Identity for my Application pool(aspNetCore).
There I gave Username, password of the account which is already found in my user groups as well as SQL Server. And i gave dbowner
rights to this account for my db.
But still i don't know why it returned 404 error.
Anyhow, The issue was fixed now.
Happy Coding :)
这篇关于ASP.NET Core Routing适用于VS IIS Express,但不适用于IIS 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!