asp.net-core-mvc

How to include controllers and views from an external project into MVC6?

孤人 提交于 2019-12-18 16:53:13
问题 I have some modules which has controllers and views. It is basically an extension for my web application. Each module is in a class library. I want to load these assemblies from my web application. But I'm without luck here. My solutions file structure is like: src | |-- Web.Common (Class Library Project) | |- Files like: filters, my own controller etc... | |-- WebApplication (ASP.NET5 WebSite) | |- wwwroot | |- Controllers | |- Views | |- etc... | |-- Module 1 (Class Library Project) | |-

asp net core export to Excel

China☆狼群 提交于 2019-12-18 15:32:56
问题 I'm not sure that this kind of question can be posted here, but I think that it might be interested to many programmers. I need a package that would provide me with an interface for creating Excel files. I looked up on nuget and found several packages, but not a single one that supports asp net core. 回答1: Please find Open XML SDK. I'm using v2.5 with ASP.NET Core + .NET4.6, but as far I know the latest version v2.7 has added support for .NET Standard 1.3 - please read the change log. More

asp net core export to Excel

和自甴很熟 提交于 2019-12-18 15:31:26
问题 I'm not sure that this kind of question can be posted here, but I think that it might be interested to many programmers. I need a package that would provide me with an interface for creating Excel files. I looked up on nuget and found several packages, but not a single one that supports asp net core. 回答1: Please find Open XML SDK. I'm using v2.5 with ASP.NET Core + .NET4.6, but as far I know the latest version v2.7 has added support for .NET Standard 1.3 - please read the change log. More

Basic Authentication in ASP.NET Core

僤鯓⒐⒋嵵緔 提交于 2019-12-18 13:53:11
问题 Question How can I implement Basic Authentication with Custom Membership in an ASP.NET Core web application? Notes In MVC 5 I was using the instructions in this article which requires adding a module in the WebConfig . I am still deploying my new MVC Core application on IIS but this approach seems not working. I also do not want to use the IIS built in support for Basic authentication , since it uses the Windows credentials. 回答1: ASP.NET Security will not include Basic Authentication

Best Way to Decouple Startup Configuration from Web Project in ASP.NET 5 and MVC 6

China☆狼群 提交于 2019-12-18 13:38:02
问题 Using MVC5, it has been very easy to create a bootstrapper project that had references to all layers, thus decoupling the UI layer from references to, lets say, infrastructure logic. The project would contain startup configuration logic, such as setting up the IoC container. The way to do this was to define a startup class: public class Startup { public static void Start() { // startup configuration (IoC etc) goes here } } And then add a line in AssemblyInfo.cs : [assembly:

Using MimeMapping in ASP.NET 5 (vNext)

放肆的年华 提交于 2019-12-18 12:45:43
问题 I'm trying to move my old mvc5 project to mvc6. Old code was: public string ContentType { get { if (!string.IsNullOrEmpty(FileName)) return MimeMapping.GetMimeMapping(FileName); return null; } } Error is The name 'MimeMapping' does not exist in the current context 回答1: The following code should work: string contentType; new FileExtensionContentTypeProvider().TryGetContentType(FileName, out contentType); return contentType ?? "application/octet-stream"; 回答2: There is a NuGet package MimeTypes

Custom Authorize filter with aspnet core

痴心易碎 提交于 2019-12-18 12:36:06
问题 Hi I am trying to create a custom authorize filter that will allow me to authorize requests coming from localhost automatically (which will be used for my tests). I found the following one for Asp.net however am having trouble porting it to asp.net core. public class MyAuthorizeAttribute : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { if (httpContext.Request.Url.IsLoopback) { // It was a local request => authorize the guy return true; } return base

How to ConfigureServices Authentication based on routes in ASP.NET Core 2.0

牧云@^-^@ 提交于 2019-12-18 12:22:24
问题 In ASP.NET Core 1.x I could use authentication methods in Configure but now in ASP.NET Core 2.0 I have to set everything in ConfigureServices and can't configure it in Configure method. For example public void ConfigureServices(IServiceCollection services) { services.AddAuthentication() .AddCookie() .AddXX(); } and then in public void Configure(IApplicationBuilder app, IHostingEnvironment env) { .... app.UseAuthentication(); } in the past, I could use something like app

Visual Studio 2015 ASP.NET 5, Gulp task not copying files from node_modules

本秂侑毒 提交于 2019-12-18 12:16:49
问题 I am attempting to alter a task runner script that I borrowed from here, however; after the task runner successfully executes in Visual Studio 2015's Task Runner Explorer -- the files are not actually copied. Here is the altered script: /// <binding BeforeBuild='copy-assets' /> "use strict"; var _ = require('lodash'), gulp = require('gulp'); gulp.task('copy-assets', function() { var assets = { js: [ './node_modules/bootstrap/dist/js/bootstrap.js', './node_modules/systemjs/dist/system.src.js',

How can I get the baseurl of my site in ASP.NET Core?

吃可爱长大的小学妹 提交于 2019-12-18 12:03:24
问题 Say my website is hosted in the mywebsite folder of www.example.com and I visit https://www.example.com/mywebsite/home/about. How do I get the base url part in an MVC controller? The part that I am looking for is https://www.example.com/mywebsite The example listed here doesn't work as we don't have access to Request.Url in ASP.NET Core 回答1: You should still be able to piece together what you need. You have access to the request object if your controller inherits from Controller . If you are