asp.net-core-mvc

APK packages is not served in ASP.NET Core MVC

妖精的绣舞 提交于 2019-12-05 11:11:39
I want to serve .apk files in my ASP.NET Core MVC project, and I can't since it returns 404. I created a simple ASP.NET Core MVC project using default template in VS 2017, and added the .apk file to wwwroot folder, and then I tried to reach it using /application.apk path, and it didn't work, while /favicon.ico works, and other static contents in that directory work, because in default template app.UseStaticFiles() is called. I then tried to change configurations, brought static contents out of wwwroot folder and put the application.apk in the root directory of the project (one folder up from

Opening a websocket channel inside MVC controller

旧城冷巷雨未停 提交于 2019-12-05 11:00:45
问题 Has anyone has any good experience with opening a websocket connection inside MVC controller? Technology stack: ASPNET Core 1.0 (RC1) MVC, dnx46, System.Net.WebSockets Why MVC instead of middleware: for overall consistency, routing, already injected repositories, an option to call private methods in the same controller. [HttpGet("v1/resources/{id}")] public async Task<IActionResult> GetAsync(string id) { var resource = await this.repository.GetAsync(id); if (resource == null) { return new

ASP.NET Core 2.2 JWT Authentication

余生颓废 提交于 2019-12-05 10:28:04
I've been learning about ASP.NET Core 2.2 recently and trying to develop a Role-Based login sample(Website + Web API) using JWT token. Definition is simple: if user's role is "admin" then it redirects to admin page. if user's role is "user" then it redirects to user page. But most of the solutions and articles I found on "JWT token with ASP.NET Core 2.2" is only for Web API. I've almost understood how JWT token works and how to implement it on Web API side from following article : http://jasonwatmore.com/post/2019/01/08/aspnet-core-22-role-based-authorization-tutorial-with-example-api Now my

No response received with JsonResult in MVC 6

浪子不回头ぞ 提交于 2019-12-05 10:08:40
I'm using ASP.NET MVC 6 in beta6. In my Startup.cs I have the following code: services.AddMvc().Configure<MvcOptions>(o => { o.OutputFormatters.RemoveAll(formatter => formatter.GetType() == typeof(JsonOutputFormatter)); var jsonOutputFormatter = new JsonOutputFormatter { SerializerSettings = { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore } }; o.OutputFormatters.Insert(0, jsonOutputFormatter); }); In my controller I have: public async Task<JsonResult> Get() { var result = new DataTablesResult(); List<MyClass> myClass = await _Repository.GetListMyClass(); result.Data =

Scaffold-DbContext creating model for table without a primary key

半腔热情 提交于 2019-12-05 10:04:24
问题 I am trying to create DBcontext and corresponding model for a particular table in ASP.NET core MVC application. This table doesn't have any primary key. I am running following Scaffold-DbContext command- Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLE_NAME -force -verbose In Package Manager Console, I can see this verbose output- ............... ............... Unable to identify the primary

Serve static files outside wwwroot, but handle PhysicalFileProvider when directory does not exist

回眸只為那壹抹淺笑 提交于 2019-12-05 09:53:01
I am trying to serve files from outside wwwroot but also handle a setup situation where the directory may not exist yet. For example, if I built a site which relies on this directory, but a user did not follow install instructions and create the directory first. For the sake of argument, let's pretend I want a simple website which has a page that will read the contents of that directory and display some files. This page might also allow you to download files from /Documents subdirectory. The example directory would be C:\Example\Documents . As this is an aspnet core mvc project, I would use

Is there any way to get request body in .NET Core FilterAttribute?

落花浮王杯 提交于 2019-12-05 08:46:00
Sample of my request http://localhost:8065/api/note POST content-type:application/json request body: { "id" : "1234", "title" : "test", "status" : "draft"} and the response should be { "msg" : "ok", "code" : 1} The action public async Task<IActionResult> Post([FromBody]NoteModel model) In order to have every request logged automatically, I create an attribute to do this job. The attribute looks like: (from Microsoft Docs ) public class SampleActionFilterAttribute : TypeFilterAttribute { public SampleActionFilterAttribute():base(typeof(SampleActionFilterImpl)) { } private class

ASP.Net Core 2 ServiceProviderOptions.ValidateScopes Property

冷暖自知 提交于 2019-12-05 08:43:05
What is ServiceProviderOptions.ValidateScopes exactly? I feel I couldn't understand completely what it does under the hood. I've come across this with a tutorial, but no explanation. Tseng I assume you are speaking about this piece of code: services.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true }); // or services.BuildServiceProvider(true); // or false ? The ASP.NET Core Provider has a mechanic which validates if a scoped service is resolved by a singleton container. ASP.NET Core has two kinds of containers. The main, singleton container which is valid for the life

How to get information about runtime .Net Core

陌路散爱 提交于 2019-12-05 08:25:31
I have an app which works on Linux and Windows. I need to know where the app is working for use difference code. Thanks You are probably looking for System.Runtime.InteropServices.RuntimeInformation with the IsOsPlatform function to do runtime checks. Have look at the video tutorial https://channel9.msdn.com/Series/aspnetmonsters/ASPNET-Monsters-Episode-46-Finding-Platform-Information of the ASP.NET Monsters. 来源: https://stackoverflow.com/questions/39207282/how-to-get-information-about-runtime-net-core

ASP.NET Core ways to handle custom response/output format in Web API

孤者浪人 提交于 2019-12-05 08:25:26
I'd like to create custom JSON format, that would wrap the response in data and would return Content-Type like vnd.myapi+json Currently I have created like a wrapper classes that I return in my controllers but it would be nicer if that could be handled under the hood: public class ApiResult<TValue> { [JsonProperty("data")] public TValue Value { get; set; } [JsonExtensionData] public Dictionary<string, object> Metadata { get; } = new Dictionary<string, object>(); public ApiResult(TValue value) { Value = value; } } [HttpGet("{id}")] public async Task<ActionResult<ApiResult<Bike>>> GetByIdAsync