asp.net-core-mvc

Asp.Net Boilerplate .Net Core 2.0 AbpAuthorizationFilter - ChallengeResult / Unauthorized

只愿长相守 提交于 2020-02-04 02:29:07
问题 I am running an Asp.Net Core 2.0 with Asp.Net Boilerplate version 3.4.0 web application. When I have an authenticated user that does not have the required permissions to access a resource, a ChallengeResult is set by the AbpAuthorizationFilter via the Abp framework. This behavior results in the user being returned to the default login page. If the user is authenticated, I would like to set a ForbidResult and redirect them to the default AccessDenied page. After reviewing my options, I see

No service for type 'Microsoft.AspNetCore.Mvc…" has been registered

只谈情不闲聊 提交于 2020-02-03 11:01:23
问题 I'm trying to test this controller method to make sure that it redirects to another controller method or has a model error. public IActionResult ResetPassword(ResetPasswordViewModel viewModel) { if (viewModel.NewPassword.Equals(viewModel.NewPasswordConfirm)) { ...do stuff return RedirectToAction("Index", "Home"); } ModelState.AddModelError("ResetError", "Your passwords did not match. Please try again"); return View(viewModel); } When I run my tests I get two different error messages. When it

Cors error in Angular 6 .Net core 2.2 App

China☆狼群 提交于 2020-02-02 13:39:43
问题 I have developed the .Net Core MVC (angular) app and .net core Api app In both apps I have enabled the CORS in both Web app and api .Net Core services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); // in Configure app.UseCors("CorsPolicy"); Angular For all Get and Post add the headers like below get(url: string, options?: any) { let headers = new Headers(); headers.append('Content-Type',

Cors error in Angular 6 .Net core 2.2 App

丶灬走出姿态 提交于 2020-02-02 13:38:12
问题 I have developed the .Net Core MVC (angular) app and .net core Api app In both apps I have enabled the CORS in both Web app and api .Net Core services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); // in Configure app.UseCors("CorsPolicy"); Angular For all Get and Post add the headers like below get(url: string, options?: any) { let headers = new Headers(); headers.append('Content-Type',

Asp.net Core Load Assembly

ⅰ亾dé卋堺 提交于 2020-02-02 12:12:46
问题 I am tring to load some .dll files from a folder: var fileNames = Directory .GetFiles(path, "*.dll", searchOption); var assemblyNames = fileNames .Select(AssemblyLoadContext.GetAssemblyName); List<Assembly> assemblies = new List<Assembly>(); foreach (AssemblyName assemblyName in assemblyNames) { assemblies.Add(Assembly.Load(assemblyName)); } But somehow the assembly cannot be loaded: FileNotFoundException, Could not load file or assembly [...] The system cannot find the file specified. How is

Returning a 404 from an explicitly typed ASP.NET Core API controller (not IActionResult)

♀尐吖头ヾ 提交于 2020-01-30 15:21:13
问题 ASP.NET Core API controllers typically return explicit types (and do so by default if you create a new project), something like: [Route("api/[controller]")] public class ThingsController : Controller { // GET api/things [HttpGet] public async Task<IEnumerable<Thing>> GetAsync() { //... } // GET api/things/5 [HttpGet("{id}")] public async Task<Thing> GetAsync(int id) { Thing thingFromDB = await GetThingFromDBAsync(); if(thingFromDB == null) return null; // This returns HTTP 204 // Process

How to upload an Excel file data into SQL Server without oledb

佐手、 提交于 2020-01-30 02:51:29
问题 I have been trying to import data from an Excel file into SQL Server with ASP.NET Core MVC. But this code just doesn't run: [HttpPost] public IActionResult Index(ICollection<IFormFile> files) { string line; using (SqlConnection con = new SqlConnection(@"Data Source=NT;Initial Catalog=StudentDB;Integrated Security=True")) { con.Open(); using (StreamReader file = new StreamReader("TestFile.xlsx")) { while ((line = file.ReadLine()) != null) { string[] fields = line.Split(','); SqlCommand cmd =

asp.net core RC2 image does not display

邮差的信 提交于 2020-01-25 12:42:22
问题 What I am trying to do is to display an image from web root folder and this is the way I am trying to do it: The following class is just experimental and is just and example for me to try it out. For now there is only one image in the folder that is being read from. As well the rootPath is taken from: _hostingEnvironment.WebRootPath public class GetRandomImageForGalleryView : IGetRandomImageFromFolder { private string rootPath; public GetRandomImageForGalleryView(string rootPath) { this

asp.net core RC2 image does not display

折月煮酒 提交于 2020-01-25 12:42:16
问题 What I am trying to do is to display an image from web root folder and this is the way I am trying to do it: The following class is just experimental and is just and example for me to try it out. For now there is only one image in the folder that is being read from. As well the rootPath is taken from: _hostingEnvironment.WebRootPath public class GetRandomImageForGalleryView : IGetRandomImageFromFolder { private string rootPath; public GetRandomImageForGalleryView(string rootPath) { this

asp.net core RC2 image does not display

99封情书 提交于 2020-01-25 12:41:49
问题 What I am trying to do is to display an image from web root folder and this is the way I am trying to do it: The following class is just experimental and is just and example for me to try it out. For now there is only one image in the folder that is being read from. As well the rootPath is taken from: _hostingEnvironment.WebRootPath public class GetRandomImageForGalleryView : IGetRandomImageFromFolder { private string rootPath; public GetRandomImageForGalleryView(string rootPath) { this