asp.net-core-mvc

Can one use Reportviewer Control in ASP.net Core

扶醉桌前 提交于 2019-12-03 11:40:39
问题 I want to make use of the Reporting Services ReportViewer control in an ASP.NET Core MVC project. The solution as proposed in other answers it to add a webform to the project. However since ASP.NET Core doesn't support webforms I cannot add the control to a webform. Is there any other workaround that might possibly assist me in using the ReportViewer control in an ASP.NET Core Web application? 回答1: Update 2019 I have ReportViewer working on ASP.NET Core on Windows, and most features (not PDF

How to access current absolute Uri from any ASP .Net Core class?

两盒软妹~` 提交于 2019-12-03 10:48:50
I am trying to figure out how to access the current absolute Uri -- i.e. the absolute url of the view that is currently being rendered -- from a user class in .Net Core 1.1 I found this link but it seems to be outdated and throws error after error: Getting absolute URLs using ASP.NET Core MVC 6 In my Startup.cs I have under ConfigureServices : services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); In my Startup.cs I have under Configure: IHttpContextAccessor httpContextAccessor = app.ApplicationServices.GetRequiredService<IHttpContextAccessor>(); Extensions.Context.Configure

How to get the current ASP.NET core controller method name inside the controller using Reflection or another accurate method

蓝咒 提交于 2019-12-03 10:17:39
I want to get the current method name of my ASP.NET Core controller I have tried getting the method name through reflection: [HttpGet] public async Task<IActionResult> CreateProcess(int catId) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; but this gives me a value of MoveNext and not CreateProcess Take note I don't want to use the ViewContext string methodName = ActionContext.RouteData.Values["action"].ToString(); as I lowercase my urls via the startup settings.The above will get me createprocess instead of CreateProcess I preferably want an easy one-liner and not

Any way to use Authorization Policies in a view in .NET Core 1.0 MVC?

瘦欲@ 提交于 2019-12-03 10:10:05
I know in controllers, you can write [Authorize("policyName")] without an issue, but is there any way to use a policy in a view? I'd rather not use User.IsInRole(...) every single time I want to authorize some HTML. Edit: Here's some code Startup.cs -- Policy Declaration services.AddAuthorization(options => { options.AddPolicy("testPolicy", policy => { policy.RequireAuthenticatedUser() .RequireRole("RoleOne", "RoleTwo", "RoleThree") .RequireClaim(ClaimTypes.Email); }); }); Admin Controller [Authorize("testPolicy")] public class AdminController : Controller { public IActionResult Index() {

How to remove all objects (reset ) from IMemoryCache in ASP.NET core

爷,独闯天下 提交于 2019-12-03 09:47:16
I can find a remove method to remove an object from IMemoryCache by its key. Is there a way to reset the whole cache and remove all objects? Edit: How to clear MemoryCache? Dispose method provided in the link gives me an exception in asp.net 5. ObjectDisposedException: Cannot access a disposed object. Object name: 'Microsoft.Extensions.Caching.Memory.MemoryCache'. https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory Section Cache dependencies Using a CancellationTokenSource allows multiple cache entries to be evicted as a group This code worked for me: public class

How to register ILogger for injection in ASP.NET MVC 6

左心房为你撑大大i 提交于 2019-12-03 09:21:22
I have a ASP.NET MVC 6 (beta-4) app. public void ConfigureServices(IServiceCollection services) { // Logging services.AddLogging(); // ... } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) { // Add the console logger. loggerfactory.AddConsole(minLevel: LogLevel.Warning); // ... } And I have a controller... public class HomeController : Controller { ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } // ... } But when I'm not getting the service registered correctly somehow: InvalidOperationException: Unable to

Create list of entities in asp.net core mvc

僤鯓⒐⒋嵵緔 提交于 2019-12-03 09:03:12
I want to create an entity in asp.net core mvc. The entity represents an exercise workout, and it has a child collection of exercise sets: public class Workout { public DateTime Date { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual ICollection<Set> Sets { get; set; } } public class Set { public int Id { get; set; } public int ExerciseId { get; set; } public int WorkoutId { get; set; } public decimal Weight { get; set; } public int Reps { get; set; } public virtual Exercise Exercise { get; set; } public virtual Workout Workout { get; set; } }

Entity Framework Core 1.0 DbContext not scoped to http request

孤者浪人 提交于 2019-12-03 08:42:16
I understood by watching this video with Rowan Miller https://channel9.msdn.com/Series/Whats-New-with-ASPNET-5/06 (at minute 22) that the way of configuring Entity Framework Core (previously known as EF7) into an ASP.NET Core 1.0 app (previously known as ASP.NET 5) in Startup.cs is as follows: public void ConfigureServices(IServiceCollection services) { //Entity Framework 7 scoped per request?? services.AddEntityFramework() .AddSqlServer() .AddDbContext<MyDbContext>(options => { options .UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]); }); //MVC 6 services.AddMvc(); }

BrowserLink does not work for ASP.NET Core on Visual Studio 2017 RTM

若如初见. 提交于 2019-12-03 08:29:53
I get the following error in the browser when I enable BrowserLink for my ASP.Net Core 1.1 application and I think because of that the BrowserLink does not work. Browser Link: Exception thrown when trying to invoke Browser Link extension callback "microsoft.visualstudio.web.browserlink.sourcemappingextensionfactory.getCssMappingData": System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.VsWebUrlUtil

ASP.NET 5 MVC 6 Generic Repository Pattern

百般思念 提交于 2019-12-03 08:26:04
Been looking every where for a tutorial or something. I've been trying to implement my old generic repository pattern for MVC5 into a new MVC6 project. I set up 3 class library's .Core , .Data and .Service , However there's an issue with IDBset , seems my intellisense doesn't like it, I tried to add System.Data and Entity framework 6 but without any luck (cant find it...confusing). After roaming google I decided to ask here, is there a tutorial with the correct way or can someone throw up a very simple MVC6 Generic Repository pattern? I have a feeling the Old method of doing it may have