asp.net-core-1.0

How to access session from a view in ASP .NET Core MVC 1.0

此生再无相见时 提交于 2019-12-10 03:18:57
问题 I am trying to access session data from inside a view. Use Case: I'm storing status messages in the session that will be displayed at the top of the page. Currently I implemented this by using a DisplayMessages() function that sets some ViewData[....] properties and calling it at the beginning of every controller action. Goal: I want to only set the status message once without needing additional code in the controller to display the messages on the next page load. So I'm trying to access the

How to read a connectionString WITH PROVIDER in .NET Core?

强颜欢笑 提交于 2019-12-10 03:14:44
问题 I added .AddJsonFile("Connections.json", optional: true, reloadOnChange: true) in public Startup(IHostingEnvironment env) Connections.json contains: { "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=DATABASE;Trusted_Connection=True;MultipleActiveResultSets=true", "COR-W81-101": "Data Source=DATASOURCE;Initial Catalog=P61_CAFM_Basic;User Id=USERID;Password=PASSWORD;Persist Security Info=False;MultipleActiveResultSets=False;Packet Size=4096;", "COR-W81-100":

Is there Session.Abandon() asp.net Core

回眸只為那壹抹淺笑 提交于 2019-12-10 01:02:37
问题 In Asp.net WebForms there is an event called Seesion_End() in global.asax, whenever session is timeout or you call Session.Abandon() this event handler is executed, i need to have similar kind of behavior in asp.net Core, is it possible? 回答1: You could clear the session by simply calling: HttpContext.Session.Clear(); 回答2: The docs cover most of this. The session timeout is set like this: services.AddSession(options => { options.IdleTimeout = TimeSpan.FromSeconds(10); }); But since it exists

How to inject IHttpContextAccessor into Autofac TenantIdentificationStrategy

霸气de小男生 提交于 2019-12-09 17:23:37
问题 I am migrating my multitenant application from Webapi to aspnet core. In webapi version I was using TenantIdentificationStrategy that identified tenants based on request path on HttpContext . Moving to aspnet core, I am able to wire-up autofac successfully. I am not able to figure out how to wireup the tenant strategy. I tried injecting IHttpContextAccessor in ConfigureServices as services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); and my strategy looks like this public class

Can I build ASP.NET Core web application using Microsoft Dotnet CLI?

喜你入骨 提交于 2019-12-09 13:42:20
问题 I have gone through some websites and found that .NET Core is using .NET CLI (.NET Command Line Interface). I have create a console application using .NET CLI and it is working fine But when I am creating an ASP.NET Core web application using Yeoman and running the command “dotnet restore” then I am getting the following error: Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 is not compatible with DNXCore,Version=v5.0. I also tried dotnet restore -s https://api.nuget.org/v3/index.json But

Entity Framework Core 1.0 DbContext not scoped to http request

我只是一个虾纸丫 提交于 2019-12-09 06:44:35
问题 I understood by watching this video with Rowan Miller https://channel9.msdn.com/Series/Whats-New-with-ASPNET-5/06 (at minute 22) that the way of configuring Entity Framework Core (previously known as EF7) into an ASP.NET Core 1.0 app (previously known as ASP.NET 5) in Startup.cs is as follows: public void ConfigureServices(IServiceCollection services) { //Entity Framework 7 scoped per request?? services.AddEntityFramework() .AddSqlServer() .AddDbContext<MyDbContext>(options => { options

SendGrid not working from Azure App Service

此生再无相见时 提交于 2019-12-08 17:57:16
问题 I am using the latest SendGrid .NET package (8.0.3) to send e-mails from my ASP.NET Core web app: public Task SendEmailAsync(string email, string subject, string message) { return Send(email, subject, message); } async Task Send(string email, string subject, string message) { dynamic sg = new SendGridAPIClient(_apiKey); var from = new Email("noreply@my.domain", "My Name"); var to = new Email(email); var content = new Content("text/html", message); var mail = new Mail(from, subject, to,

System.Runtime reference in .Net Core MVC application

守給你的承諾、 提交于 2019-12-08 04:13:48
问题 I recently updated my .Net Core (i believe 10 RTM, 1.0.0-preview2-003121?) MVC solution to a VS2017 solution. After several attempts, using multiple project.json versions and .Net Core package versions, I finally got the application working again in the new environment. Ofcourse, except for 1 error still poping up when using some objects in my Razor views: As you can see, the error says that I am missing a reference to System.Runtime. I tried adding this reference to my project in multiple

In ASP.NET Core, does the IoC ASP Startup Class solve what the Managed Extensibility Framework solved with a catalog and container?

六眼飞鱼酱① 提交于 2019-12-08 04:00:08
问题 I have read this, MEF (Managed Extensibility Framework) vs IoC/DI but it is dated. Since then MEF was added to Core. When I look at MEF and the IoC in ASP.NET Core, I cannot tell a lot of differences for a plugin architecture. Both "wire-up" dependencies. If I wanted to create a plugin in a Core application using IoC (the built in IoC), why not just change my ConfigureService methods? Is that the same as decorating imports and exports in MEF? How is composition different here, in 2017 (close

Specifying the url (port) that a asp.net core 1.0 WebAPI.exe should use in program.cs for both prod and dev

天涯浪子 提交于 2019-12-07 12:08:22
问题 I am doing the following in my asp.net core 1.0 web api (.NET Framework) program.cs to specify which port I want my web api exe to run in for development purposes only: public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .UseUrls(new string[1] { "http://*:12012" }) .Build(); host.Run(); } However, when I publish to production this line causes the WebAPI to error