如何为每个请求关闭ASP.NET完成的日志记录,例如:
INFO 09:38:41用户个人资料可用.使用'C:\ Users\xxxx xxxx\AppData\Local\ASP.NET\DataProtection-Keys'作为密钥存储库,使用Windows DPAPI加密静态密钥.
DEBUG 9时38分41秒开始托管
DEBUG 9时38分41秒开始托管
INFO 9时38分41秒开始请求HTTP/1.1 GET 的http://本地主机:23369 /
INFO 9时38分41秒开始请求HTTP/1.1 DEBUG HTTP: // localhost:23369 / text/html DEBUG 09:38:41不支持
DEBUG请求DEBUG 09:38:41请求路径/与支持的文件类型不匹配
DEBUG 09:38:41请求成功匹配路线名称'default'和模板'{controller = Home}/{action = Index}/{id?}'.DEBUG 09:38:41请求成功匹配路线名称'default'和模板'{controller = Home}/{action = Index}/{id?}'.DEBUG 9时38分41秒执行动作Forums.Controllers.HomeController.Index
DEBUG 9时38分41秒执行动作Forums.Controllers.HomeController.Index
INFO 9时38分41秒执行一个带有参数的操作方法Forums.Controllers.HomeController.Index() - ModelState is
Valid'INFO 09:38:41执行动作方法Forums.Controllers.HomeController.Index
..
我还没找到如何关闭这个日志...
这是我班上的Configure方法Startup:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddProvider(new Log4NetProvider());
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// For more details …Run Code Online (Sandbox Code Playgroud) 我在.NET Core中创建了一个空的 Web应用程序,wwwroot我的index.html没有加载为默认页面,只有在我明确调用它时才会加载.
这是我的project.json
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
Run Code Online (Sandbox Code Playgroud)
在这里我的启动:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 …Run Code Online (Sandbox Code Playgroud) 我在Oracle中使用Entity Framework 4.3代码优先.我收到以下错误:
System.InvalidOperationException:类型为"WidgetDistributor.WidgetEntity"的属性"WidgetSequence"上的ForeignKeyAttribute无效.在依赖类型"WidgetDistributor.WidgetEntity"上找不到外键名称"WIDGETSEQUENCE_ID".Name值应该是以逗号分隔的外键属性名称列表.
我的实体是这样的:
[Table("WIDGETENTITIES")]
public class WidgetEntity {
[Column("WIDGETENTITY_ID")]
public int Id { get; set; }
[ForeignKey("WIDGETSEQUENCE_ID")]
public WidgetSequence Sequence { get; set; }
// and other properties that map correctly
}
[Table("WIDGETSEQUENCES")]
public class WidgetSequence {
[Column("WIDGETSEQUENCE_ID")]
public int Id { get; set; }
[Column("NUMBER")]
public int Number { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的代码似乎正确.我做错了什么,这里?
根据这篇文章, intellisense也应该在新的VS 2015上工作,但到目前为止我只获得了角度对象的intellisense而不是依赖项或我的自定义模块.

这是我做的:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References 我还将文件添加到与angular.js相同的位置,但它仍然无法正常工作.我在这种情况下的问题是,我应该在哪里放置文件?在只有我的angular.js的角度公用文件夹上,或在我的dev角文件夹中,从凉亭下载的所有文件都在.
我还尝试将它直接添加到Implicit(Web)引用组的tools/options/text editor/javascriptr/intellisense/reference菜单中,但它仍然无效.
在我的项目中,我在src文件夹中有以下文件夹结构:
作为旁注,我没有/ scripts文件夹,因此没有/scripts/_references.js文件
.
这是我的代码:
public async Task<IActionResult> Index(ICollection<IFormFile> files)
{
foreach (var file in files)
uploaddb(file);
var uploads = Path.Combine(_environment.WebRootPath, "uploads");
foreach (var file in files)
{
if (file.Length > 0)
{
var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
await file.SaveAsAsync(Path.Combine(uploads, fileName));
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我使用以下代码将此文件转换为字节数组:
var filepath = Path.Combine(_environment.WebRootPath, "uploads/Book1.xlsx");
byte[] fileBytes = System.IO.File.ReadAllBytes(filepath);
string s = Convert.ToBase64String(fileBytes);
Run Code Online (Sandbox Code Playgroud)
然后我将此代码上传到我的nosql数据库.这一切都运行正常,但问题是我不想保存文件.而不是我想直接将文件上传到我的数据库.如果我可以直接将文件转换为字节数组而不保存它是可能的.
public async Task<IActionResult> Index(ICollection<IFormFile> files)
{
foreach (var file in files)
uploaddb(file);
var uploads = Path.Combine(_environment.WebRootPath, "uploads");
foreach (var file in files)
{
if (file.Length > …Run Code Online (Sandbox Code Playgroud) 我有一个完整的ASP.NET MVC应用程序(.NET Core,ASP.NET MVC 6),它在Visual Studio(使用IISExpress)中运行良好.
我现在想要一个控制台应用程序,它接受MVC应用程序并托管它(自托管).
到目前为止,我认为不ViewComponent解决这两个问题TagHelper.这有什么替代品吗?需要参数并返回的东西HtmlString?
我没有看到任何有害的东西:
@helper foo(string something) {
<div>Say @something</div>
}
var emailbody = classfilenameinAppCodefolder.foo("hello"); //store result in a variable for further processes
Run Code Online (Sandbox Code Playgroud)
现在我相信它在RC之前暂时删除.https://github.com/aspnet/Razor/issues/281和https://github.com/aspnet/Mvc/issues/1130嗯!它更好.我希望有人正在努力.没有@helper,建立大型HtmlString或"模板"将是一个严重的痛苦.
注意:部分视图似乎没有成功.我认为它只会渲染视图而不是返回视图变量.
其次,App_Code文件夹发生了什么?
随着Blazor的发明,我想知道这两种语言之间是否有显着的效率(代码的创建和代码的实际编译/执行)?
https://github.com/SteveSanderson/Blazor
如果有人真正实现了它,你是否已经进行了任何性能测试,或者与普通的Razor相比,是否有轶事(是的,抱歉,我要求此道歉)对代码编写过程的反馈?
我想在尝试执行无效操作时向客户端返回403 Forbidden.我需要使用的方法是什么?
我通过互联网搜索但我发现只有MVC 5:
如果您的web api方法的返回类型是HttpResponseMessage,那么您需要使用以下代码:
Run Code Online (Sandbox Code Playgroud)return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "RFID is disabled for this site."); Or if the return type for your web api method is IHttpActionResult then you need to use the below code return StatusCode(HttpStatusCode.Forbidden,"RFID is disabled for this site.");如何为IActionResult类型返回403:
Run Code Online (Sandbox Code Playgroud)public IActionResult Put(string userid, [FromBody]Setting setting) { var result = _SettingsRepository.Update(userid, setting); if (result == true) { return Ok(201); } else { return BadRequest(); } }
在我的ASP.NET Core应用程序中,我有一个像这样的控制器动作:
[HttpPost]
public async Task<IActionResult> CreateSubscriber([FromBody] SubscriberDef subscriber)
{
//...implementation removed
var link = Url.Link("SubscriberLink", new { id = subscriber.ID });
return Created(link, null);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码按预期工作.但是,如果我使用内置方法"CreatedAtRoute",那么我得到一个例外:
[HttpPost]
public async Task<IActionResult> CreateSubscriber([FromBody] SubscriberDef subscriber)
{
//...implementation removed
return CreatedAtRoute("SubscriberLink", new { id = subscriber.ID });
}
Run Code Online (Sandbox Code Playgroud)
例外是:
System.InvalidOperationException:没有路由匹配提供的值.
该异常导致服务返回500状态代码.
在任何一种情况下都是相同的路由,所以我不知道为什么第一个例子正常工作而第二个例子没有.
我project.json包含这个:
"frameworks": {
"dnx46": { },
"dnxcore50": { }
},
Run Code Online (Sandbox Code Playgroud)
为了参考起见,命名路由由两部分组成.首先是控制器前缀:
[Route("api/[controller]")]
public class SubscribersController : Controller
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
其次是GET操作,其中实际"SubscriberLink"路由命名为:
[HttpGet("{id}", Name = "SubscriberLink")] …Run Code Online (Sandbox Code Playgroud)