asp.net-core-mvc

.NET Core MVC Page Not Refreshing After Changes

天大地大妈咪最大 提交于 2019-12-17 23:37:31
问题 I'm building a .NET Core MVC on the latest version 2.2. I have a problem when I make changes to the CSHTML file and refresh the page, my changes are not reflected in the browser. I have to restart the project in order to see my changes. This has been happening for a while now so I'm not exactly sure what change caused this issue. I've tried using the chrome's "Empty Cache and Hard Reload" as well as other browsers to no avail. This happens on Windows and Mac using both Visual Studio for Mac

Show ASP.NET 5 error page in Azure web app

时光毁灭记忆、已成空白 提交于 2019-12-17 22:58:35
问题 I am getting a 500 Internal Server Error when deploying our ASP.NET 5 web application to an Azure Web App. How do I get the details and stacktrace for this exception? I have done the following but with no luck: Using the diagnostics error page on startup: app.UseErrorPage(); Setting ASPNET_ENV in Azure portal: Using DNX beta 6. 回答1: In case this helps someone, I've found out that if you're using ASP.NET RC1 and you're using Azure WebApps and add an App setting called Hosting:Environment with

How to get absolute path in ASP.Net Core alternative way for Server.MapPath

有些话、适合烂在心里 提交于 2019-12-17 22:27:33
问题 How to get absolute path in ASP net core alternative way for Server.MapPath I have tried to use IHostingEnvironment but it doesn't give proper result. IHostingEnvironment env = new HostingEnvironment(); var str1 = env.ContentRootPath; // Null var str2 = env.WebRootPath; // Null, both doesn't give any result I have one image file (Sample.PNG) in wwwroot folder I need to get this absolute path. 回答1: Inject IHostingEnvironment as a dependency into the dependent class. The framework will populate

asp.net core custom model binder just for one property

笑着哭i 提交于 2019-12-17 20:44:30
问题 I have a simple model for my asp.net core controller: [HttpPost] public async Task<DefaultResponse> AddCourse([FromBody]CourseDto dto) { var response = await _courseService.AddCourse(dto); return response; } My model is : public class CourseDto { public int Id { get; set; } public string Name { get; set; } public string Genre { get; set; } public string Duration { get; set; } public string Level { get; set; } public string AgeRange { get; set; } public string Notes { get; set; } public bool

MVC 6 Hosted on IIS HTTP Error 500.19

青春壹個敷衍的年華 提交于 2019-12-17 18:53:34
问题 Am getting HTTP Error 500.19 when accessing MVC 6 app in IIS on Windows 10. In IIS I have set the App pool to 'No Managed Code' The app is hosted in the root of a new Web Site. I published the app using Visual Studio 2015 with the following settings. Configuration : Debug Target DNX Version: dnx-clr-win-x64.1.0.0-rc1-update1 The web.config is the boilerplate provided by Visual Studio <?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name=

Change injected object at runtime

跟風遠走 提交于 2019-12-17 18:43:33
问题 I want to have multiples implementation of the IUserRepository each implementation will work with a database type either MongoDB or any SQL database. To do this I have ITenant interface that have a connection string and other tenant configuration. The tenant is been injected into IUserRepository either MongoDB or any SQLDB implementation. What I need to know is how properly change the injected repository to choose the database base on the tenant. Interfaces public interface IUserRepository {

Dependency injection, inject with parameters

独自空忆成欢 提交于 2019-12-17 18:13:01
问题 I'm using vNext implementation of DI. How to pass parameters to constructor? For example, i have class: public class RedisCacheProvider : ICacheProvider { private readonly string _connectionString; public RedisCacheProvider(string connectionString) { _connectionString = connectionString; } //interface methods implementation... } And service register: services.AddSingleton<ICacheProvider, RedisCacheProvider>(); How to pass parameter to constructor of RedisCacheProvider class? For example for

How to get the Development/Staging/production Hosting Environment in ConfigureServices

早过忘川 提交于 2019-12-17 17:46:16
问题 How do I get the Development/Staging/production Hosting Environment in the ConfigureServices method in Startup? public void ConfigureServices(IServiceCollection services) { // Which environment are we running under? } The ConfigureServices method only takes a single IServiceCollection parameter. 回答1: You can easily access it in ConfigureServices, just persist it to a property during Startup method which is called first and gets it passed in, then you can access the property from

How to Seed Users and Roles with Code First Migration using Identity ASP.NET Core

ぃ、小莉子 提交于 2019-12-17 17:29:13
问题 I have created a new clean asp.net 5 project (rc1-final). Using Identity Authentication I just have the ApplicationDbContext.cs with the following code: public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { protected override void OnModelCreating(ModelBuilder builder) { // On event model creating base.OnModelCreating(builder); } } Please note ApplicationDbContext use IdentityDbContext and not DbContext. There is any IdentityConfig.cs. Where i need to put the classic

Authorizing a user depending on the action name

耗尽温柔 提交于 2019-12-17 17:26:11
问题 I have many controllers with many actions. Each action has it's own Role ( Role name = ControllerName.actionName ). In previous versions I could test if the current user can acces an action or not using a "generic" AuthorizeAttribute : public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { string currentAction = actionContext.ActionDescriptor.ActionName; string currentController = actionContext.ActionDescriptor.ControllerDescriptor.ControllerName;