我正在使用带有启用 CORS 的 c# web api 的 angular web 项目。
我的所有 CORS 在所有调用中都能正常工作,除非我将文件上传到异步任务。这是我所指的方法。
[HttpPost]
public async Task<HttpResponseMessage> UploadFile(){
    //code
}
我得到的错误是:
请求的资源上不存在“Access-Control-Allow-Origin”标头。
所以显然我什至不允许调用我的 UploadFile 方法。
在小文件上,调用有效,响应中出现“Access-Control-Allow-Origin”,但在 60 mb + 的较大文件上则不然。
我正在使用 XMLHttpRequest 进行 web api 调用。
var xhr = new XMLHttpRequest();
        if (xhr.upload) {
            xhr.upload.filename = $scope.files[i].name;
            xhr.upload.addEventListener('progress', function (evt) {
                var percentComplete = Math.round(evt.loaded * 100 / evt.total);
                $scope.uploadCompleteValues[this.filename] = percentComplete;
                console.log(percentComplete + '%');
                if (!$scope.$$phase) { $scope.$apply(); } 
            }, false);
        }
        xhr.onreadystatechange = function (ev) {
            if (xhr.readyState …我在c#中编写集成测试,当我在对话框中的某些元素上使用click()方法时,没有任何反应,我没有错误.它将单击对话框中的某些元素,但不会单击其他元素.我认为如果没有正确选择它们那么它会抛出异常但它运行平稳并说测试通过,即使它从未实际点击按钮.该对话框是一个iframe.
我想也许它试图点击一个尚未显示或启用的按钮,所以我在click()调用之前添加了这个:
 _driver.SwitchTo().Frame(_frameElement);
     _wait.Until(d =>
    {
      var shippingInfoButton = d.FindElement(By.CssSelector("input[title ='Info']"));
      return shippingInfoButton.Displayed && shippingInfoButton.Enabled;
    });
       var infoButton = _driver.FindElement(By.CssSelector("input[title ='Info']"));
        ScrollToElement(infoButton);
        infoButton.Click();
再次,这运行没有抛出异常,所以我假设它已找到元素,它显示和启用.
如果您需要更多信息,请告诉我.谢谢
我正在运行asp.net core 2 Web API作为Windows服务。通过IIS调试时,我可以读取配置值,没有问题。
但是,一旦将其作为服务运行,我将无法获得任何价值。
appsettings.json
{
  "Database": {
    "DatabaseName": "testdb",
    "DatabaseServer": "localhost",
    "DatabaseUserName": "admin",
    "DatabasePassword": "admin"
  }
}
 public string GetConnectionString()
    {
        var databaseName = Configuration["Database:DatabaseName"];
        var databaseServer = Configuration["Database:DatabaseServer"];
        var username = Configuration["Database:DatabaseUserName"];
        var password = Configuration["Database:DatabasePassword"];
        return $"Data Source={databaseServer};Initial Catalog={databaseName};Persist Security Info=True;User ID={username};Password={password};MultipleActiveResultSets=True";
    }
不知道为什么发布应用程序后为什么我无法读取这些值。在发布的appsettings.json文件中,值在那里。
这是我的startup.cs。我的印象是,我不必在新的asp.net核心2中引用appSettings.json文件。感谢您的帮助。
public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
    public IConfiguration Configuration { get; }
    // This method gets called by the runtime. Use this method to …c# configuration asp.net-core asp.net-core-webapi asp.net-core-mvc-2.0