我正在尝试在新的asp .net CORE/MVC 6项目中设置一个基本的swagger API文档,并从swagger UI接收500错误:
500 : http://localhost:4405/swagger/v1/swagger.json
我的启动类中包含以下代码:
using Swashbuckle.SwaggerGen;
using Swashbuckle.SwaggerGen.XmlComments;
using Swashbuckle.Application;
....
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSwaggerGen();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Blog Test Api",
Description = "A test API for this blogpost"
});
});
}
Run Code Online (Sandbox Code Playgroud)
然后在Configure下:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
....
app.UseSwaggerGen();
app.UseSwaggerUi();
....
}
Run Code Online (Sandbox Code Playgroud)
当我构建并运行项目时,当我转到swagger/UI/index.html时,UI会出现,但会显示上面的500错误.当我转到swagger/v1/swagger.json链接时,控制台会给出以下500错误:
Failed to load resource: the server responded with a status of 500 (Internal Server Error) …
如何Area在ASP.NET Core中使用?
我有一个需要管理员部分的应用.此部分要求将其视图放置在该区域中.所有以请求开头的请求Admin/都需要重定向到该区域.
asp.net-mvc-routing asp.net-mvc-areas asp.net-core-mvc asp.net-core
我正在使用.Net Core构建MVC应用程序,我需要生成迁移脚本.
使用EF6,我确实运行了命令
update-database -script
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用.net时也是如此.
Update-Database:找不到与参数名称'script'匹配的参数
你知道EF7是否有相同的产品吗?
.net entity-framework entity-framework-core asp.net-core-mvc asp.net-core
ASP.NET Core API控制器通常返回显式类型(默认情况下,如果您创建一个新项目),如下所示:
[Route("api/[controller]")]
public class ThingsController : Controller
{
// GET api/things
[HttpGet]
public async Task<IEnumerable<Thing>> GetAsync()
{
//...
}
// GET api/things/5
[HttpGet("{id}")]
public async Task<Thing> GetAsync(int id)
{
Thing thingFromDB = await GetThingFromDBAsync();
if(thingFromDB == null)
return null; // This returns HTTP 204
// Process thingFromDB, blah blah blah
return thing;
}
// POST api/things
[HttpPost]
public void Post([FromBody]Thing thing)
{
//..
}
//... and so on...
}
Run Code Online (Sandbox Code Playgroud)
问题是return null;- 它返回HTTP 204:成功,没有内容.
然后,许多客户端Javascript组件将其视为成功,因此代码如下:
const …Run Code Online (Sandbox Code Playgroud) c# http-status-code-404 asp.net-core-mvc asp.net-core asp.net-core-webapi
我在asp.net核心应用程序中使用EF7(实体框架核心).能否请您指出执行存储过程的正确方法?旧的方法与ObjectParameters和((IObjectContextAdapter)this).ObjectContext.ExecuteFunction不工作.
基于这篇文章,我正在尝试IActionFilter为ASP.NET Core 创建一个实现,它可以处理控制器上标记的属性和控制器的操作.虽然读取控制器的属性很容易,但我无法找到一种方法来读取action方法中定义的属性.
这是我现在的代码:
public sealed class ActionFilterDispatcher : IActionFilter
{
private readonly Func<Type, IEnumerable> container;
public ActionFilterDispatcher(Func<Type, IEnumerable> container)
{
this.container = container;
}
public void OnActionExecuting(ActionExecutingContext context)
{
var attributes = context.Controller.GetType().GetCustomAttributes(true);
attributes = attributes.Append(/* how to read attributes from action method? */);
foreach (var attribute in attributes)
{
Type filterType = typeof(IActionFilter<>).MakeGenericType(attribute.GetType());
IEnumerable filters = this.container.Invoke(filterType);
foreach (dynamic actionFilter in filters)
{
actionFilter.OnActionExecuting((dynamic)attribute, context);
}
}
}
public void OnActionExecuted(ActionExecutedContext context)
{
throw …Run Code Online (Sandbox Code Playgroud) 在RC2相同的代码返回json格式与camel case.在netcore 1.0发布之后,我启动了新项目,同样的代码以小写形式返回json.
尝试了多个解决方案,但没有一个正在使用 web-api-serialize-properties-starting-from-lowercase-letter
我们有一台Windows 2012 R2计算机.我有一个现有的ASP.NET核心站点,它有一个运行的已发布的ASP.NET核心站点.
但是,当我在更改后一个月后再次发布到网站时,我无法访问该网站并在浏览器中收到以下错误
HTTP错误502.5 - 进程失败
有关详细信息,请访问:http://go.microsoft.com/fwlink/?LinkID = 808681
如果我登录到服务器并单击我部署目录中的exe,它会打开一个命令提示符并在端口5000上显示我的站点.如果我在http:// localhost:5000上访问该站点,它可以正常工作,所以问题是要做与IIS而不是网站本身.
如果我登录到服务器,我可以在Windows EventViewer中看到以下内容
具有物理根"D:\ Sites\MySite"的应用程序'MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE/MySite'无法使用命令行'"%LAUNCHER_PATH%"%LAUNCHER_ARGS%'启动进程,ErrorCode ='0x80070002:0.
当我访问浏览器错误消息中的链接时,它提到重新安装.net Core Hosting捆绑包,我做了.但是,浏览器中的错误消息是相同的.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore requestTimeout="02:00:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
当我查看我的应用程序日志文件夹时,每次尝试访问此站点时都会创建一个stdout文件,但每次它的大小为0KB且为空内容时.
为什么IIS拒绝在以前工作的地方突然工作,但如果我直接访问编译的exe,应用程序是否有效?
我想要一个访问Configuration对象的简单静态类.所有配置信息都已从Startup类中的appsettings.json文件中读取.我只需要一种简单的方法来访问它.这可能吗?
namespace MyNamespace
{
public static class Config
{
public string Username => Configuration["Username"];
public string Password => Configuration["Password"];
}
}
Run Code Online (Sandbox Code Playgroud)
应用中的其他任何地方:
string username = Config.Username;
string password = Config.Password;
Run Code Online (Sandbox Code Playgroud) 在SO上有一个问题为什么Razor Pages是在Asp.net Core 2.0中创建Web UI的推荐方法?史蒂夫史密斯从少量文件的角度解释了使用Razor Pages而不是完整MVC的好处.
我一直在使用Razor Pages,并注意到尽管Razor Page简洁的优点,但在自定义路由,结构化文件夹和复杂视图模型(页面模型似乎混乱)方面有点复杂.
所以,问题是:
如果一些有经验的人分享了关于使用Razor Pages更好地理解这个框架的想法(优点和缺点),我也将不胜感激.
asp.net-core-mvc ×10
asp.net-core ×6
c# ×3
.net ×2
json ×1
json.net ×1
razor-pages ×1
swashbuckle ×1