我正在遵循本指南.我Startup
在API项目中使用了一个appsettings.json
配置文件.
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.ReadFrom.Configuration(Configuration)
.CreateLogger();
}
Run Code Online (Sandbox Code Playgroud)
我正在看的特别部分是env.ContentRootPath
.我做了一些挖掘,看起来我appsettings.json
实际上并没有复制到bin
文件夹,但这很好,因为ContentRootPath
返回MySolution\src\MyProject.Api\
,这是appsettings.json
文件所在的位置.
所以在我的集成测试项目中,我有这个测试:
public class TestShould
{
private readonly TestServer _server;
private readonly HttpClient _client;
public TestShould()
{
_server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
_client = _server.CreateClient();
}
[Fact]
public async Task …
Run Code Online (Sandbox Code Playgroud) c# configuration integration-testing appsettings asp.net-core
如果我只浏览应用程序上的某些页面,它大约为500MB.这些页面中的许多页面访问数据库,但此时,我只有大约几行用于10个表,大多数存储字符串和一些小于50KB的小图标.
当我下载文件时,会出现真正的问题.该文件大约为140MB,并存储为varbinary(MAX)
数据库中的文件.内存使用量突然升至1.3GB,瞬间降至1GB.该操作的代码如下:
public ActionResult DownloadIpa(int buildId)
{
var build = _unitOfWork.Repository<Build>().GetById(buildId);
var buildFiles = _unitOfWork.Repository<BuildFiles>().GetById(buildId);
if (buildFiles == null)
{
throw new HttpException(404, "Item not found");
}
var app = _unitOfWork.Repository<App>().GetById(build.AppId);
var fileName = app.Name + ".ipa";
app.Downloads++;
_unitOfWork.Repository<App>().Update(app);
_unitOfWork.Save();
return DownloadFile(buildFiles.Ipa, fileName);
}
private ActionResult DownloadFile(byte[] file, string fileName, string type = "application/octet-stream")
{
if (file == null)
{
throw new HttpException(500, "Empty file");
}
if (fileName.Equals(""))
{
throw new HttpException(500, "No name");
}
return File(file, type, …
Run Code Online (Sandbox Code Playgroud) 我正在使用本地服务器,我需要通过HTTPS访问特定的URL,其余的通过HTTP访问.我已将Visual Studio配置为使用IIS Express,因此我可以使用HTTP/SSL.
我有一个像这样的方法:
[RequireHttps]
public ActionResult SomeHttpsMethod()
{
//Do something
}
Run Code Online (Sandbox Code Playgroud)
在另一个地方我:
var url = Url.Action("SomeHttpsMethod", "SomeHttpsController", new { someParams }, Request.Url.Scheme);
Run Code Online (Sandbox Code Playgroud)
如果我使用访问我的网站HTTP
也就是http://localhost:httpport
,我仍然可以HTTP
从返回Request.Url.Scheme
代替HTTPS
.它是如何工作的?
显然,如果我使用HTTPS
ie来访问我的网站ie https://localhost:sslport
,HTTPS
则返回(这是我想要的)但我不想访问该网站HTTPS
,仅针对该特定的URL /控制器方法.
我遇到的情况类似于未调用的未捕获异常处理程序,但他是Mac应用程序,而我是iOS应用程序。解决方案是使用ExceptionHandler
框架,但是在iOS上不可用。
我有一个全新的iOS单视图应用程序,它只有几行代码,所以我不会粘贴整个文件。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&handler);
@throw NSInternalInconsistencyException;
return YES;
}
void handler()
{
NSLog(@"hello world");
}
Run Code Online (Sandbox Code Playgroud)
因此,didFinishLaunchingWithOptions
我设置了自定义异常处理程序,然后强制崩溃。然后将异常处理程序打印hello world
到控制台,但这不会发生。在处理程序中放置断点表明执行未进入方法。但是无论如何,异常都会打印到控制台(默认操作)。
2014-07-24 08:58:25.476 Exception[430:70b] *** Terminating app due to uncaught exception of class '__NSCFConstantString'
libc++abi.dylib: terminating with uncaught exception of type __NSCFConstantString
Run Code Online (Sandbox Code Playgroud)
我的处理程序在某处之后是否可以默认设置另一个异常处理程序?
更新
我决定将强制崩溃的方式从更改NSInternalInconsistencyException
为[[NSArray arrayWithObject:@"object"] objectAtIndex:1];
。现在将调用该处理程序并将hello world
其打印到控制台。
所以现在的问题是,为什么没有NSINternalInconsistencyException
导致处理程序被调用?错误略有不同:
2014-07-24 10:13:51.333 Exception[1474:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** …
Run Code Online (Sandbox Code Playgroud) 最初我有一个可以发布到Azure的ASP.NET 5项目,没有任何问题.然后我决定将DAL分成一个单独的类项目,但遇到了许多依赖问题.然后我决定用空白类库创建一个空白项目,看看我是否能解决问题所在,但我甚至都无法发布.
脚步:
这是项目结构:
由此产生的ASP.NET 5 project.json
:
"frameworks": {
"dnx451": {
"dependencies": {
"ClassLibrary1": "1.0.0-*"
}
},
"dnxcore50": { }
},
Run Code Online (Sandbox Code Playgroud)
所以它成功引用,我可以在自托管上构建和部署,但如果我尝试将其发布到Azure,我会收到以下错误消息:
The "Dnu" task failed unexpectedly.
System.Exception:
Microsoft .NET Development Utility CLR-x86-1.0.0-beta6-12256
Copying to output path C:\Users\MyUserDir\AppData\Local\Temp\PublishTemp
Time elapsed 00:00:04.1309210
at Microsoft.DNX.Tasks.Dnu.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder. <ExecuteInstantiatedTask>d__26.MoveNext()
Run Code Online (Sandbox Code Playgroud)
我使用的是Visual Studio 2015和ASP.NET 5 Beta 7.
编辑: 经过一些游戏,我不认为我的答案是正确的.我现在意识到有些情况下不能使用新类型的类库,例如现有的旧类库,这对端口来说可能是不切实际的.有办法做到这一点吗?
我已经尝试过dnu publish
,它发布完全没问题.然后我将输出FTP到服务器上,然后它给了我一个Runtime Error
.我尝试使用Visual Studio远程调试它.我可以看到当我访问网站时抛出异常,但我无法确定问题究竟是什么.抛出的第一个例外之一是:
Exception thrown: 'System.InvalidOperationException' in AspNet.Loader.dll …
c# ×4
asp.net ×2
asp.net-core ×2
asp.net-mvc ×2
appsettings ×1
azure ×1
exception ×1
handler ×1
https ×1
ios ×1
memory ×1
ssl ×1