API设置缺少了什么?

huangapple go评论57阅读模式
英文:

API setup missing something?

问题

我第一次设置 Web API,并且有另一个项目作为参考。这是一个使用 .NET 框架的项目,将具有 React 前端。我正在使用 Visual Studio 和 IIS Express 运行它。

启动 API 项目时没有构建错误。它已添加了 Swagger,以便我可以测试数据库调用,所以我知道 API 本身是正常工作的。但是我漏掉了一些东西,因为我希望为其添加更多安全性。

我尝试验证身份验证,想使用集成的 Windows 身份验证。当我设置断点时,HttpContext.Current 中的用户从未设置并且未经身份验证,因此无法添加任何授权过滤器。

我回到了只有基本的空 API 项目,其中删除了前端网页,以查看是否删除了什么,但出现了相同的问题。因此,要么我再次删除了它,要么我确实漏掉了添加的内容。

我不确定在哪里查找缺少什么,所以如果有任何指示,将不胜感激。

左边的浏览器是我期望的,右边的浏览器是我看到的。
API设置缺少了什么?

我不需要启用目录浏览,所以看到 403.14 - Forbidden 是可以的。但显然我错过了一些东西才导致这一点。有没有更好的方法来找出是哪个资源/依赖项导致了这个错误?

我还可以看到工作版本请求的 URL 是我期望的,但另一个只是一个 /。如果这是错误,有没有解决这个问题的方法?

如果需要,我可以添加代码片段,但我还没有添加,因为我不确定问题出在哪里。

英文:

I am setting up a web api for the first time and I have another project for reference. It is a .NET framework project that will have a React frontend. I am running it using Visual Studio and IIS Express.

I have no build errors when I start the api project. It has swagger added so I can test database calls, so I know the api itself is working. But I am missing adding something as I am looking to add more security to it.

I am trying to verify authentication and I want to use integrated Windows authentication. When I set a break point, the user in the HttpContext.Current is never set and is never authenticated, so I can't add any authorization filters.

I went back to just the basic empty api project that has the frontend web pages removed to see if I removed something and it shows the same issue. So I either removed it again or I am actually missing adding something.

I am not sure where to look for what is missing, so any pointers would be appreciated.

The left browser is what I am expecting and the right browser is what I am seeing.
API设置缺少了什么?

I don't need the directory browse turned on, so seeing a 403.14 - Forbidden is fine. But I am clearly missing something to get to that point. Is there a better way to figure out which resource/dependency is causing this error?

I can also see the working version requested url is what I am expecting, but the other is just a /.
Is there a way to resolve that if this is the error?

I can add code snippets if needed, but I haven't yet as I am not sure where the issue is.

答案1

得分: 0

我最终通过使用空白测试 web API 找到了答案,看看我可能留下的不必要的部分。该项目是使用以下选项设置的:

在删除视图等,使其严格成为 API 项目之后,我开始删除引用(并清除相关错误),并查看每次更改后构建的情况。

在 App_Start 文件夹下,有一些额外的文件,在我用来比较的项目中并不存在 - FilterConfig 和 RouteConfig - 这两者也在 Global.asax 中调用。

我删除了 Global.asax 中的所有三者的调用,然后我能够看到预期的 HTTP 错误页面。

英文:

I ended up finding the answer using blank test web apis to see what I may have left in that wasn't needed. The project was set up using this option:
API设置缺少了什么?

After removing the views, etc., to make it strictly an api project. I started removing references (and clearing the associated errors) and seeing what happened with the build after each change.

Under the App_Start folder, there were some additional files that weren't present in the project I had for comparison - FilterConfig, and RouteConfig - which were also called in the Global.asax.

I removed the call in Global.asax for all three and I was able to see the expected http error page.
API设置缺少了什么?

huangapple
  • 本文由 发表于 2023年2月18日 00:58:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75487171.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定