asp.net-core-mvc

Apply Authorize filter on all controllers within an area

我与影子孤独终老i 提交于 2019-12-25 03:27:40
问题 How can I force authorization on all controllers within an area? Specifically, I would like to configure an AuthorizeFilter to be applied on the 'admin' area as part of the Startup.ConfigureServices() method. 回答1: One way do to this is with the use of a custom IControllerModelConvention public class AuthorizeAreaConvention : IControllerModelConvention { private readonly string _area; private readonly string _policy; public AuthorizeAreaConvention(string area, string policy) { _area = area;

Store and display HTML string while avoiding JS, in ASP.Net Core 2

依然范特西╮ 提交于 2019-12-25 01:33:49
问题 I wish to store a formatted text using a Rich-Text editor (QuillJS) and while displaying back it should be rendered as HTML. By default the views encode the HTML to avoid JS Injection, and so the data is being treated as a plain string. How do i manage to store and display / render the data as HTML, while at the same time filtering any JS in the string ? I tried searching for api's but couldn't find any help. Secondly, these days it's getting increasing difficult getting to the documentation

Azure deployment : Could not load file or assembly 'dnx.clr.managed' or one of its dependencies. The system cannot find the file specified

二次信任 提交于 2019-12-25 00:35:53
问题 Create a new ASP.NET 5 (MVC 6) app and deploy to Azure. You get the HTTP 500 exception. If you create a web.config file in the wwwroot folder with the following markup: <configuration> <system.web> <customErrors mode="Off"/> </system.web> </configuration> You get the the exception in the title. 回答1: One way to get this error is to deploy a 64 bit version (either Core or x86) to a free or shared web app. If you create the azure web app in the publish dialog, VS creates a free web app (which

Problems Posting in a Model with AJAX in ASP.NET CORE MVC

╄→尐↘猪︶ㄣ 提交于 2019-12-25 00:25:58
问题 I'm having trouble doing a Post from a Complex Model using JAX in Asp.net. The model has some properties that represent other models, but at the moment, I only need to initialize them with NULL. I do not know what is missing, but my controller is getting "null" value ... There is some problem in the conversion done on the Client side. Does anyone know how to help me? var pessoaContatoViewModel = { Id: 0, PessoaId: 0, FormaContatoId: formaContatoId, FormaContatoDescricao: '', FormasContatos:

Manually instantiate a Controller in MVC 6 alpha4

人盡茶涼 提交于 2019-12-25 00:04:59
问题 I am doing some experimentation with MVC 6 alpha 4. Trying to activate a controller manually and returning it instead of HomeController but this doesn't work. Any help please.. So far I have created my own controller factory with this code. public class MyControllerFactory : IControllerFactory { public object CreateController(ActionContext actionContext) { var actionDescriptor = actionContext.ActionDescriptor as Microsoft.AspNet.Mvc.ReflectedActionDescriptor; Type controllerType = Type

How to add authorization to RazorPages?

回眸只為那壹抹淺笑 提交于 2019-12-24 23:13:55
问题 I have looked at the current official Microsoft Docs and was unable to find anything properly covering how to handle authorization for RazorPages. I figured out that you can add the AuthorizeAttribute to the PageModel like so: // using Microsoft.AspNetCore.Authorization [Authorize] public class IndexModel : PageModel { ... } I don't want to repeat this for every page. Is there a better way? 回答1: You can configure authorization under the ConfigureServices method. Here is an example : services

How can I order asp.net core runs a method once per-day?

巧了我就是萌 提交于 2019-12-24 22:05:13
问题 My asp.net core program needs to collect all the IP which access the website pre-day. I need to output the IP list to a txt file when a day is over. Therefore, the program should run a method to save the IP list once per-day. How should I design it? In my opinion, I will add a looping task in the startup.cs and set the Task.Delay to 24 hours(one day). Should I do it like this? Thank you. 回答1: This is how I implement scheduler task in ASP.Net Core. Please note that you have to know how to use

Input(float) gets converted to integer while saving

本小妞迷上赌 提交于 2019-12-24 20:39:33
问题 The problem: When the information of the form is sent to the POST Action, the float variables lose their decimal point and gets converted to an integer instead of a float . Information: This is the class that contains the definition of the variables: PUnit and CoinValue : public class Device { [Key] public int DeviceID { get; set; } [Display(Name = "Precio por Jugada")] public float PUnit { get; set; } public float CoinValue { get; set; } } In the view I present a collection of this class,

How to force re authentication between ASP Net Core 2.0 MVC web app and Azure AD

瘦欲@ 提交于 2019-12-24 19:41:18
问题 I have an ASP.Net Core MVC web application which uses Azure AD for authentication. I have just received a new requirement to force user to reauthenticate before entering some sensitive information (the button to enter this new information calls a controller action that initialises a new view model and returns a partial view into a bootstrap modal). I have followed this article which provides a great guide for achieving this very requirement. I had to make some tweaks to get it to work with

Why getting value like this [1] in AngularJS

冷暖自知 提交于 2019-12-24 18:19:32
问题 I need to get id from table but I am getting id like this [1] . I need to get 1 only. Controller public JsonResult GetLineManagerId(string LineManagerId) { var lineManagerId = db.Employees .Where(x => x.FirstName == LineManagerId) .Select(x =>x.Id); return Json(lineManagerId); } Angular $scope.GetLineManagerId = function (LineManagerId) { $http.get('/Official/GetLineManagerId?LineManagerId=' + LineManagerId).then(function (data) { console.log(data); $scope.lineManagerId = data.data; $scope