asp.net-core-mvc

Is there a session start equivalent in .Net Core MVC 2.1?

孤者浪人 提交于 2019-12-07 13:32:51
问题 In MVC 5 you could assign a value to session in global.asx when the session started. Is there a way you can do this in .Net Core MVC? I have session configured but in the middleware it seems to get called on every request. 回答1: nercan's solution will work, but I think I found a solution that requires less code and may have other advantages. First, wrap DistributedSessionStore like this: using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Session; using Microsoft

How to self-host ASP.NET 5 MVC6 application

非 Y 不嫁゛ 提交于 2019-12-07 12:32:38
问题 Just started learning ASP.NET 5 / MVC 6 I'm curious about self-hosting such an app outside of IIS - as a Windows service. Should I be using TopShelf for that, like it was the case with OWIN/Katana apps, or does ASP.NET 5 provide some built-in self-hosting (as a service) options via a NuGet package? 回答1: You can use the Kestrel library for self-hosting. Add dependency to the library in the project.json file: "dependencies": { "EntityFramework.Commands": "7.0.0-rc1-final", // Dependencies

Deploy .NET Core ASP.NET Website - HTTP Error 502.5 - Process Failure

北慕城南 提交于 2019-12-07 12:03:17
问题 I'm trying to publish the template project "ASP.NET Core Web Application (.NET Framework)" from Visual Studio 2015 to IIS. I use the Visual Studio publish to File System feature. I'm using Windows 10. I followed the guide from here. I set up a website in IIS and changed the Application Pool .NET CLR Version to No Managed Code I instaled the .NET Core Windows Server Hosting bundle I restarted my machine. I get this error: I added a logs folder, but no logs get created. Any ideas on how I can

Custom DateTime model binder in ASP.NET Core 1 (RTM)

流过昼夜 提交于 2019-12-07 11:30:00
问题 I'm writing and ASP.NET Core 1 application, which has a Web API Controller where supplier will post data. This is a simplified version of the Model class to which I will bind the incoming data: public class Lead { public int SupplierId { get; set; } public DateTime Date { get; set; } } The problem is that the dates will be posted with German formatting, for instance, 30.09.2016 . I do not want to set the global culture of the application to de-DE because a) I'm not German, and b) the rest of

Visual Studio 2015/ TFS 2013 not ignoring bower_components in ASP.NET 5 projects

余生长醉 提交于 2019-12-07 10:17:06
问题 Visual Studio 2015 is not ignoring bower_components folder although it is ignoring node_modules so I don't know what is wrong. This is the content of my project.json { "webroot": "wwwroot", "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Mvc": "6.0.0-beta7", "Microsoft.AspNet.Server.IIS": "1.0.0-beta7", "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7", "Microsoft.AspNet.StaticFiles": "1.0.0-beta7" }, "commands": { "web": "Microsoft.AspNet.Hosting --config hosting.ini" },

ASP .NET Core: CORS headers only for certain static file types

帅比萌擦擦* 提交于 2019-12-07 10:00:02
问题 I have an ASP .NET Core self-hosted project. I am serving up content from a static folder (no problem). It serves up images cross-site without issue (CORS header shows up). However, for some file types, such as JSON, they CORS headers don't show up, and the client site can't see the content. If I rename the file to an unknown type (such as JSONX), it gets served with CORS headers, no problem. How can I get this thing to serve everything with a CORS header? I have the following CORS policy set

Remote Validation in ASPNET 5 MVC 6

大城市里の小女人 提交于 2019-12-07 09:34:23
问题 Can not find JsonRequestBehavior in aspnet 5 I am trying to implement remote validation demo and it seem like Microsoft.AspNet.Mvc does not contain JsonRequestBehavior enumeration. But it does exist in System.Web.Mvc namespace in previous version of MVC Model: public class Person : Entity { [Required] [StringLength(512)] [Remote("IsAllowedName", "Validation", ErrorMessage="This name is not allowed!" )] [Display(Name = "First (and middle) name")] public String FirstMidName { get; set; } View:

Redirect from exception filter

不羁的心 提交于 2019-12-07 09:16:36
问题 I'm using ASP.NET Core. One of my controllers calls into services which throw various exceptions. I want to handle them in an exception filter (not middleware). public class MyHandlerAttribute : ExceptionFilterAttribute { public override void OnException(ExceptionContext c) { if (c.Exception is FooException) { // redirect with arguments to here } else if (c.Exception is FooException) { // redirect with arguments to there } else { // redirect to main error action without arguments, as 500 }

ASP.NET Core 2 - develop using custom domain names and ssl using IISExpress

坚强是说给别人听的谎言 提交于 2019-12-07 08:44:52
问题 I want to be able to develop locally using a custom domain and ssl rather than localhost. How can I setup a custom domain + ssl in VS Solution instead of localhost? 回答1: Simple Setup - Using Server URLs If you want to associate your server to use all the IP addresses assigned to the server/web host then you can do this: var host = new WebHostBuilder() .UseUrls("http://*:80", "http://localhost") .UseKestrel() .UseIISIntegration() .Build(); Note: If you don't want all IP addresses, then you can

Session Store IQueryable in HttpContext

浪尽此生 提交于 2019-12-07 08:32:24
I am migrating project from Net MVC to MVC Core 2. How do I set IQueryable in Sessions? In Net MVC it was the following, public ActionResult CurrentOwners_Read([DataSourceRequest]DataSourceRequest request, int propertyID) { if (propertyID == 0) { throw new ArgumentNullException("propertyID"); } IQueryable<PropertyOwnerRoleViewModel> allResult = (IQueryable<PropertyOwnerRoleViewModel>)HttpContext.Session.GetString(_currentOwnersResult).AsQueryable(); if (allResult == null) { PropertyOwnerManager propertyOwnerManager = new PropertyOwnerManager(); allResult = propertyOwnerManager