asp.net-core-1.0

How to return an Excel file from a WebAPI ASP.NET Core

醉酒当歌 提交于 2019-11-30 14:50:19
问题 In similar questions, with this code works to download a PDF: I'm testing with local files (.xlsx, .pdf, .zip) inside the Controller folder. Similar Question Here [HttpGet("downloadPDF")] public FileResult TestDownloadPCF() { HttpContext.Response.ContentType = "application/pdf"; FileContentResult result = new FileContentResult (System.IO.File.ReadAllBytes("Controllers/test.pdf"), "application/pdf") { FileDownloadName = "test.pdf" }; return result; } But when another file?, for example an

Pass parameter to Partial View in ASP.NET Core

扶醉桌前 提交于 2019-11-30 13:52:54
On an ASP.NET Core 2.0 application I need to render a partial view and pass a few parameters: @Html.Partial("Form", new { File = "file.pdf" }) On the partial view I tried to access it using: @Model.File And I get the error: RuntimeBinderException: 'object' does not contain a definition for 'File' If I simply use on my partial: @Model I get the following printed on the page: { File = file.pdf } So there the model is being passed and there is a property File in it. So what am I missing? You are passing untyped (anonymous type) data to partial view. You cannot use @Model.File . Instead, you will

How to deal with environment differences when deploying asp.net core application?

帅比萌擦擦* 提交于 2019-11-30 12:17:34
问题 Is there a way to change the environment settings when deploying ASP.NET Core application (like config file transformations using debug/release build)? What would be the best approach for maintaining multiple environment settings in .NET Core applications (something similar to <appSettings file="local.config"> for local, staging and production)? 回答1: The central configuration file is the appsettings.json and you can have multiple files, like appsettings.Production.json etc, which will be

Authenticate against Active Directory in .NET Core 1.0 application?

两盒软妹~` 提交于 2019-11-30 11:50:16
问题 With the recent release of .NET Core 1.0, we're in the process of migrating our RC1 applications to the final release. The only piece we can't seem to figure out is how to integrate Active Directory authentication. Previously in the RC1 applications, we had used the System.DirectoryServices.AccountManagement library to handle the LDAP authorization queries. However, we can no longer mix this library with .NET Core v1. Generally, what is the best way to integrate Active Directory

Solving error “Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1”

被刻印的时光 ゝ 提交于 2019-11-30 11:43:45
I have an ASP.NET Core 1.0 complete application running using net461 references. Now I am trying to add another framework - netcoreapp1.0 . For this, I have updated my project.json like this: { "userSecretsId":"", "version":"2.4.0-*", "buildOptions":{ "emitEntryPoint":true, "preserveCompilationContext":true }, "dependencies":{ "Microsoft.ApplicationInsights.AspNetCore":"1.0.0", "Microsoft.AspNetCore.Authentication.Cookies":"1.0.0", "Microsoft.AspNetCore.Diagnostics":"1.0.0", "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore":"1.0.0", "Microsoft.AspNetCore.Identity":"1.0.0", "Microsoft

Read appsettings.json in Main Program.cs

你。 提交于 2019-11-30 10:56:11
First of all my main purpose is to setup the IP and Port for my application dynamically. I'm using IConfiguration to inject a json config file, like some tutorial mentioned. However, I can't retrieve the configuration in Program.cs, because my WebHostBuilder will use the StartUp and Url at the same time. So at the time the host build up, there is nothing in my configuration. WebProtocolSettings settings_Web = new WebProtocolSettings(); var host = new WebHostBuilder() .UseIISIntegration() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>() .UseUrls(settings_Web

Basic Authentication in ASP.NET Core

前提是你 提交于 2019-11-30 10:44:02
Question How can I implement Basic Authentication with Custom Membership in an ASP.NET Core web application? Notes In MVC 5 I was using the instructions in this article which requires adding a module in the WebConfig . I am still deploying my new MVC Core application on IIS but this approach seems not working. I also do not want to use the IIS built in support for Basic authentication , since it uses the Windows credentials. ASP.NET Security will not include Basic Authentication middleware due to its potential insecurity and performance problems. If you require Basic Authentication middleware

ASP.NET Core Configuration Section in Startup

人盡茶涼 提交于 2019-11-30 10:43:51
I am migrating a ASP.NET 5 RC1 project to ASP.NET Core, and have come across an interesting issue I've not yet seen, or found a solution for. In order to use configuration settings within Startup I have previously retrived the configuration the following way // Works fine for DI both in ASP.NET 5 RC1 and ASP.NET Core services.Configure<SomeConfigurationClass>(Configuration.GetSection("SomeConfigurationSection")); // How I previous retrieved the configuration for use in startup. // No longer available in ASP.NET Core var someConfigurationToUseLater = Configuration.Get<SomeConfigurationClass>(

ASP .NET Core 1.0 RTM Localization not working

♀尐吖头ヾ 提交于 2019-11-30 08:36:02
问题 I've been trying to implement localization for my asp .NET Core 1.0 RTM web app following microsofts documentation and I just can not get it to work. The problem I'm having is that it's always displaying strings from the english resource file no matter how I try setting the culture. If anyone has 5 minutes of their time, I'd be really grateful for your input. Here's my Startup.cs content that regards the localization: public void ConfigureServices(IServiceCollection services) { ... services

Asp.Net core get RouteData value from url

霸气de小男生 提交于 2019-11-30 08:01:54
I'm wokring on a new Asp.Net core mvc app. I defined a route with a custom constraint, which sets current app culture from the url. I'm trying to manage localization for my app by creating a custom IRequestCultureProvider which looks like this : public class MyCustomRequestCultureProvider : IRequestCultureProvider { public Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext) { var language= httpContext.GetRouteValue("language"); var result = new ProviderCultureResult(language, language); return Task.FromResult(result); } } My MyCustomRequestCultureProvider is hit