asp.net-core-mvc

ASP.NET Core Identity Add custom user roles on application startup

点点圈 提交于 2019-12-04 08:57:54
问题 In an ASP.NET Core application, I want to create certain roles as a basis to manage different user-permissions. Sadly, the documentation inform detailled how to use custom roles e.g. in controllers/actions, but not how to create them. I found out that I can use RoleManager<IdentityRole> for this, where the instance gets automatically injected in a controller-constructor, when its defined and ASP.NET Core identity is registered in the application. This let me add a custom role like this: var

User is authenticated but where is the access token?

我的未来我决定 提交于 2019-12-04 08:53:28
I have a web Application which authenticates a user to an Identity Server 4, using an implicit client. I need the access token for this user so that I can make a call to another API. To be clear: I have an identity Server. Created using Identity server 4. I have the web app in question created in Asp .net core mvc. API created in .net core. The Web application authenticates the user against the identity server. Once they are authenticated we use bearer tokens to access the API. services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddAuthentication(options => {

ASP.NET 5 MVC6 Custom CSS & Javascript placing convention

喜夏-厌秋 提交于 2019-12-04 08:33:54
So I'm playing around with MVC6, and I've added bower.json & grunt.json, I've created my grunt tasks for generating my jQuery & bootstrap.css and its all sitting in the wwwroot folder as i expected. But what about things like my site.css & my main.js files, the files that I will add to for the project over time. What convention are people using when choosing a directory for this stuff? Are we to add a Content folder and drop it in? Is there something I'm missing, that i should also be using Grunt / bower for? I do have app and vendor folders outside wwwroot. In vendor, I customize libraries

How to gzip static content in ASP.NET Core in a self host environment

你。 提交于 2019-12-04 08:31:20
问题 Is there are way to serve gzip static cotent when using self host environment to publish an ASP.NET Core website? 回答1: [Edit 2016-11-13] There is another way to serve gzipped files that replaces steps 2 and 3. It's basically quite the same idea, but there is a nuget package that does it all for you readily available. It basically checks if the is .gz or .br file that matches the requested one. If it exists it returns it with the appropriate headers. It does verify that the request has a

Should my custom ASP.Net 5 MVC 6 Tag Helpers have an asp- prefix?

末鹿安然 提交于 2019-12-04 07:47:22
I've been reading about the new support for Tag Helpers in MVC 6 and now need to create my own. I see that the built in tag helpers for existing HTML elements are all prefixed with "asp-" For example: <a asp-controller="Home" asp-action="Index">Home</a> But what about my own custom tag helpers. Should I also prefix those with "asp-" to show that it is running on the server. Or should this be reserved for framework attributes? Should I create my own project/company named prefix instead? Is there any guidance on this subject that I have missed? Tag helpers that target existing HTML elements

ASP.NET Core Application Lifecycle

依然范特西╮ 提交于 2019-12-04 07:46:13
问题 Is there any current "ASP.NET Core" document(s) about the life cycle? I would like to be able to tie into the life cycle at the right points. Is it similar to the existing ASP.NET MVC 5 life cycle? http://www-asp.azureedge.net/v-2016-09-01-001/media/4773381/lifecycle-of-an-aspnet-mvc-5-application.pdf 回答1: Here are few links I found related to ASP.NET Core lifecycle though this is not complete description and I'm searching for more. ASP.NET Core apps are console apps running on Kestrel so you

How to change/create custom FileProvider in .NET Core that's domain dependant (i.e. one web app serving multiple site rendering logics)

廉价感情. 提交于 2019-12-04 07:35:53
I'm currently creating a multi-tenant web app using .NET Core. And is facing a problem: 1) The Web App serves different views and logics based on a set of domain names . 2) The views are MVC views and stored in Azure Blob Storage 3) The multiples sites share the same .NET Core MVC controllers therefore only the Razor views are different with small logics. Questions.... A) Is that possible? I created a MiddleWare to manipulate however I couldn't assign FileProviders on context level properly because the file provider should be domain dependant. B) Or, rather than thinking and attempting through

ASP.NET Core serving a file outside of the project directory

删除回忆录丶 提交于 2019-12-04 07:30:19
In my ASP.NET Core project I am trying to serve an html file like this: public IActionResult Index() { return File("c:/path/to/index.html", "text/html"); } This results in an Error: FileNotFoundException: Could not find file: c:/path/to/index.html Pasting the path from the ErrorMessage into my browser I am able to open the file, so the file is clearly there. The only way I have been able to serve the file is placing it in wwwroot in the project folder and serving it like this: public IActionResult Index() { return File("index.html", "text/html"); } I have already changed the folder I serve

I'm lost. What happened to ASP.NET MVC 5?

孤街浪徒 提交于 2019-12-04 07:28:52
问题 I've been keeping my head down working on various projects and apparently Microsoft has been busy making some big changes and it's confusing the hell out of me. ASP.NET Core first came onto my radar when I installed Visual Studio 2017 last year and went to create a new project and suddenly had choices of .NET Framework, .NET Standard, and .NET Core. So I looked into them a little and saw that the latter two are, in some way, abbreviated versions of the full framework. I read this post by

Format date within View in ASP.NET Core MVC

北战南征 提交于 2019-12-04 07:21:26
I have problem in regarding with converting the datetime to date using a model. Model from Class Library public partial class LoanContract { [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")] public DateTime LoanDateStart { get; set; } } Model from Project public class ModelLoan { public LoanContract loanContract { get; set; } } Code in controller myList.loanContract = new LoanContract { LoanDateStart = DateTime.Today }; View: <input disabled type="date" asp-for="loanContract.LoanDateStart" id="dpDateNow" class="form-control" /> It show like this: yyyy-MM-dd what I want to achieve is that I