asp.net-core-mvc

.Net CORE Dapper Connection String?

家住魔仙堡 提交于 2019-12-01 08:34:05
I am setting up my first .NET Core application. I am going to user Dapper (1.50.0-rc2) for the ORM. I have added the following to my appsettings.json file. "Data": { "DefaultConnection": { "ConnectionString": "user id=exampleusername;password=examplepassword;Data Source=db.example.com;Database=exampledb;" } }, I am confused at how to get the value of ConnectionString . As .NET Core is so new, online examples are all over the place and none seem to actually cover this. I have a sample Console App for .NET core on my GitHub repository Setup phase var builder = new ConfigurationBuilder()

Get property of applicationuser from the asp.net core identity

不羁岁月 提交于 2019-12-01 08:03:44
I found this link: How to get the current logged in user Id ASP.NET Core But the answers are all OUTDATED! And this SO post can not neither be a solution, its just a boilerplate workaround: How should I access my ApplicationUser properties from within my MVC 6 Views? In the mvc action: base.User is not of type ApplicationUser neither is base.User.Identity. Both can not be casted into ApplicationUser. So how can I access my custom properties put inside the applicationuser object when logged in? For the controller, have a dependency on UserManager<ApplicationUser> . Then, you can access the

Ajax.ActionLink alternative with mvc core

余生颓废 提交于 2019-12-01 07:37:24
In MVC5 there is @Ajax.ActionLink that is useful to update just a partial view instead of reloading the whole View. Apparently in MVC6 is not supported anymore. I have tried using @Html.ActionLink like the following but it doesn't update the form, it return just the partial view: View: @Html.ActionLink("Update", "GetEnvironment", "Environments", new { id = Model.Id }, new { data_ajax = "true", data_ajax_method = "GET", data_ajax_mode = "replace", data_ajax_update = "environment-container", @class = "btn btn-danger" }) control: public async Task<ActionResult> GetEnvironment(int? id) { var

Working with IViewLocationExpander in mvc

偶尔善良 提交于 2019-12-01 07:09:11
问题 I want to render the view from custom location, so for that I have implemented IViewLocationExpander interface in a class. I have registered the same class in startup file as follows. Startup.cs file public void ConfigureServices(IServiceCollection services) { ..... //Render view from custom location. services.Configure<RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new CustomViewLocationExpander()); }); .... } CustomViewLocationExpander Class public class

How to gain access to Asp.Net Core encryption keys?

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:58:43
问题 A cookie provided by call: await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal); is stored in encrypted state. How to get encryption key? IMPORTANT : this question has grown from my original question about cookie decryption. Thanks to Ron C and his great answer. 回答1: Gaining Access to the Keys By default the .net core framework goes to great lengths to keep the keys private and to help the developer to avoid any need for handling the keys. This is good as it's

Package restore failed. Rolling back package changes for 'myproject' in vs 2017 in MVC Core

∥☆過路亽.° 提交于 2019-12-01 06:54:59
问题 I install VS 2017 15.3 and create new MVC Core project I try install each new package from package manager console or Manage NuGet package manager window and try to update all package or one of listed package, that show on update tab ,after many times I get that error : Severity Code Description Project File Line Suppression State Error Package restore failed. Rolling back package changes for 'Sun'. 0 Try to re create new project in MVC -web or API project - and try to update all package but

MVC6 TagHelpers with disposable

匆匆过客 提交于 2019-12-01 06:40:38
In the older MVC HTML Helpers, one could use IDisposable to wrap content - for example the BeginForm helper would automatically wrap *stuff* with a closing form tag <% using (Html.BeginForm()) {%> *stuff* <% } %> Is this wrapping of content supported with MVC6 TagHelpers? For example I would like this <widget-box title="My Title">Yay for content!</widget-box> to be expanded into a bootstrap widget-box with wrapping divs: <div class="widget-box"> <div class="widget-header"> <h4 class="widget-title">My Title</h4> </div> <div class="widget-body"> <div class="widget-main"> Yay for content! </div>

How to discern between model binding errors and model validation errors?

倖福魔咒の 提交于 2019-12-01 06:37:57
问题 I'm implementing a REST API project using ASP.NET Core MVC 2.0, and I'd like to return a 400 status code if model binding failed (because the request is syntactically wrong) and a 422 status code if model validation failed (because the request is syntactically correct but contains unacceptable values). As an example, given an action like [HttpPut("{id}")] public async Task<IActionResult> UpdateAsync( [FromRoute] int id, [FromBody] ThingModel model) I'd like to return a 400 status code when

ASP.NET Core 2.0: static file (site.min.js) not found

人盡茶涼 提交于 2019-12-01 06:37:57
问题 I want to deploy an ASP.NET Core web application via publishing profiles in Visual Studio 2017. Everything is copied to the destination folder and works fine, except the "site.js" file. In the destination folder, I see in the wwwroot/js folder both site.js and site.min.js, but the latter is empty. I also get a console error in the browser: Failed to load resource: the server responded with a status of 404 (Not Found) site.min.js In page source however I see the file loaded correctly: <script

Tag Helpers - Self closing HTML tags is a bad habit?

只谈情不闲聊 提交于 2019-12-01 06:37:41
I am incorporating TagHelpers in my MVC vNext project, and I realized they don't work when I self close the HTML tags. @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" <label asp-for="FirstName"/> <!-- self closing tag --> <span asp-validation-for="FirstName"/> <!-- self closing tag --> And, insteand when I put the closing tags, I see the values being displayed. <label asp-for="FirstName"></label> <span asp-validation-for="FirstName"></span> Generated HTML <label for="FirstName">FirstName</label> <span class="field-validation-error" data-valmsg-for="FirstName" data-valmsg-replace="true">