asp.net-core-mvc

Net Core: How to Convert TagBuilder to String in C#?

给你一囗甜甜゛ 提交于 2019-12-11 15:26:08
问题 Is there a native way to convert Tagbuilder to String in Net Core? This only is for ASP Net 5. Convert IHtmlContent/TagBuilder to string in C# Convert value of TagBuilder into a String I think Microsoft had a replacement function for this in Net Core public static string GetString(IHtmlContent content) { using (var writer = new System.IO.StringWriter()) { content.WriteTo(writer, HtmlEncoder.Default); return writer.ToString(); } } 回答1: The same WriteTo method is available in aspnetcore. You

Updating IMemoryCache once an entity has changed

安稳与你 提交于 2019-12-11 15:23:40
问题 I have a CacheService that uses GetOrCreateAsync to create cache based on a key. I am caching a photograph entity, which has a byte[] property. This caches fine and is retrieved as expected. However if the photograph entity is updated, the cache still retains the old entity as you would expect because it has not expired, how can I force an update to the cache upon save of this entity? Do I remove the existing cached entity and re-add the updated one? Example of my FromCacheAsync method in my

Assigning a user to a Role inside asp.net core will return this error “You do not have access to this resource.”

对着背影说爱祢 提交于 2019-12-11 15:21:33
问题 I created a new asp.net core web application which uses individual user accounts. now i am trying to implement a simple role assignment scenario. so i register a test user, where the user got added inside the AspNetUser table:- then i add a new Role named "Administrator" inside the AspNetRole:- then i added a new AspNetUserRole to link the user to the Role:- then i added the following Authorize annotation on the About action method:- [Authorize(Roles = "Administrator")] public IActionResult

Custom error code pages with message

倖福魔咒の 提交于 2019-12-11 15:19:29
问题 I am trying to create a custom error code page that displays a message I pass to it in my .NET Core MVC 1.1 application. I setup custom error code pages support in the Startup.cs class file and then created a simple view in a controller that does public IActionResult Example1 => NotFound("Some custom error message") . I expected this message to be pushed to the controller however this is not the case. Calling NotFound() without any parameters hits the error controller but as soon as I pass a

Using remote attribute in .net core razor pages. The Parameter does not get value in Action Method of Controller

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 15:13:46
问题 I am using Remote Attribute validation The method is invoked successfully on textchange event. However, the parameters in the action method of the controller does not get the value of the field. Here is the Action Method in the HomeController.cs. When invoked the Name parameter remains null . I will be pleased if someone solve this problem [AcceptVerbs("Get", "Post")] public async Task<ActionResult> IsExist(string Name) { List<Keywords> keywords = new List<Keywords>(); HttpClient client =

ViewData & Model does not exist in the current context

假如想象 提交于 2019-12-11 15:13:38
问题 I have a .Net Core 1.1 project using VS 2017 EF Core. When I created a new view, I received the does not exist in current context error on the ViewData, the Model, and even the @model. In trying to fix the problem, I ended up updating my packages which only gave me more errors to resolve. I'm not running .Net Core 2.0 because of the update. The other views in my project are not having this issue. I created only one other view and I ended up having the same problem with it, but just on @model

How to parse byte[] array from model with IFormFile from viewmodel for file uploading controller?

∥☆過路亽.° 提交于 2019-12-11 13:35:09
问题 I have Core MVC application, when for specific entity I have following model: public class Aktualnosci { public long ID { get; set; } public string Tytul { get; set; } public string Tresc { get; set; } public DateTime Dzien { get; set; } public byte[] AktualnosciImage { get; set; } } For uploading the image I am using IFormFile property in my viewmodel, that is called by controller, according to the documentation from >>HERE<<: public class AktualnosciCreateVM { public long ID { get; set; }

Aspnet Core with Adfs 2016 OpenId can't sign out

亡梦爱人 提交于 2019-12-11 13:19:05
问题 I setup an MVC project with Aspnet Core targeting Net461. Authentication is configured to use Adfs from a Windows Server 2016 system. I managed to get sign in working, however, when I click sign out I am given a page cannot be displayed error. Browsing back to the home url shows that the user is still logged in also. Any suggestions? 回答1: You might find this sample useful (even though it is for Azure ADFS, it works for local installs as well): https://github.com/Azure-Samples/active-directory

Create custom route attribute in ASP.NET Core 2

点点圈 提交于 2019-12-11 12:56:47
问题 We have a bunch of endpoints where we'd like to do the exact same thing for each of them: Register them as a route and verify that the user has access to them. Very condensed our issue can be condensed to us having something like this: [HttpGet, Route(EntityId.First)] [HttpGet, Route(EntityId.Second)] [VerifyAccessFilter(EntityId.First, EntityId.Second)] public async Task<IActionResult> Endpoint() { return Ok(); } But would much rather like something like: [RouteAndVerify(EntityId.First,

Add dll to MVC6 or use old web service

可紊 提交于 2019-12-11 12:48:23
问题 I need to reference a dll which calls an old web service (not svc, but the older one). I'm not quite sure how to go about doing that. I'm using the RC1 version. I could call the web service directly but I'm not sure how to do that either in MVC6. If I add the dll directly I get the error: The name '*' does not exist in the current context FieldOps.DNX Core 5.0 Here's what part of my project.json looks like where the library added is called "MyLibrary": "frameworks": { "dnx451": {