kandi X-RAY | AspNetCore.Docs Summary
kandi X-RAY | AspNetCore.Docs Summary
Documentation for ASP.NET Core
Top functions reviewed by kandi - BETA
AspNetCore.Docs Key Features
AspNetCore.Docs Examples and Code Snippets
Trending Discussions on AspNetCore.Docs
This is an example on dotnet. github.com/dotnet... I work it on version net-6.0
The result of the validation check is false because the navigational properties of the class participate in the validation. I implemented a simple experiment on net-5.0 - navigational properties are not reflected in the result. But, maybe I'm wrong.
How to solve this problem correctly?...
ANSWERAnswered 2022-Feb-03 at 09:28
Not sure this answers your question or not. But would suggest you create a Data Transfer Object (DTO) class rather than directly use the (generated) Database object class.
The DTO class is designed based on what value (schema) API is expected to receive. And this DTO class would also be used for doing the first-level data validation such as Required, Range and etc. (without involving validation against database)
normally I would put the code for seeding users in the
OnModelCreating() Its not an issue with
identity's DbContextfrom the
App's DbContext, which has added two DbContexts and some confusion.
public UseManagementDbContext(DbContextOptions options) : base(options)// security/users separation
public AppDbContext(DbContextOptions options) : base(options)
But when you have two separate DbContexts, How do I seed the user / role data?
IdentityDbContext-- this has all the
context for seeding
AppDbContext-- this does NOT have
context, but my Migrations use this context.
Can you please help how to seed the user and role data, and is part of the migrations or startup etc.
Update: using core 6 sample, @Zhi Lv - how do I retrofit into
program.cs my seedData when the app is fired up
Program.cs was from created originally from the ASP Core 3.1 template, it looks like this, what should I refactor, (oddly in the link at MS, there are no class name brackets, so where does my seed get setup and invoked from?
ANSWERAnswered 2022-Jan-18 at 06:06
To seed the user and role data, you can create a static class, like this:
I have a .NET 5.0 Blazor client app and I am unable to get the
AuthorizeView tag to work.
I have scaffolded identity pages as well:
I am using a custom identity implementation that uses Cosmos Db: https://github.com/pierodetomi/efcore-identity-cosmos
I know that Authorization with roles in the Blazor client project template is an issue: https://github.com/dotnet/AspNetCore.Docs/issues/17649#issuecomment-612442543
I tried workarounds as mentioned in the above Github issue thread and the following SO answer: https://stackoverflow.com/a/64798061/6181928
...still, I am unable to get it to work.
IsInRoleAsync method is not even called after logging in to the application. I have applied a breakpoint on its implementation in the custom
CosmosUserStore class and it doesn't get hit.
The browser console shows this after logging in to the application with the admin user:
ANSWERAnswered 2022-Jan-03 at 13:28
Paste this into your Index page so you can see the information for your user:
I'm trying to create an ASP.NET Core (3.1) web application that accepts file uploads and then breaks it into chunks to send to Sharepoint via MS Graph API. There are a few other posts here that address the similar questions but they assume a certain level of .NET knowledge that I don't have just yet. So I'm hoping someone can help me cobble something together.
Configure Web server & app to Accept Large Files
I have done the following to allow IIS Express to upload up to 2GB files:
a) created a web.config file with the following code:...
ANSWERAnswered 2021-Nov-25 at 11:33
I've implemented a similar large file controller but using mongoDB GridFS.
In any case, streaming is the way to go for large files because it is fast and lightweight. And yes, the best option is to save the files on your server storage before you send. One suggestion is, add some validations to allow specefic extensions and restrict execution permissions.
Back to your questions:
The entire file is read into an IFormFile, which is a C# representation of the file used to process or save the file.
The resources (disk, memory) used by file uploads depend on the number and size of concurrent file uploads. If an app attempts to buffer too many uploads, the site crashes when it runs out of memory or disk space. If the size or frequency of file uploads is exhausting app resources, use streaming.
The CopyToAsync method enables you to perform resource-intensive I/O operations without blocking the main thread.
Here you have examples.
I followed this official documentation for providing translation to data annotation constraints.
Everything works fine, except a title in the response that is not translated. You can see this title marked in the following picture. (i.e. One or more validation errors occurred.)
This title somehow is added automatically by .Net Core.
I don't know where is it or even if it is possible to localize it or not. You can see the error message related to the password is in German in the picture but title is not.
You can find the sample code here.
FYI: I even put an entry in my
SharedResource.resx with the name
One or more validation errors occurred., however, didn't work.
ANSWERAnswered 2021-Nov-07 at 21:18
It looks like this text cannot be translated. Here is a link to the source code: https://github.com/dotnet/aspnetcore/blob/a450cb69b5e4549f5515cdb057a68771f56cefd7/src/Http/Http.Extensions/src/HttpValidationProblemDetails.cs
I'm confused by the example in the documentation here that describes how to add claims using
The sample code shows how to extend the
ANSWERAnswered 2021-Nov-05 at 09:56
So I have written a simple Azure Function (AF) that accepts (via Http Post method) an IFormCollection, loops through the file collection, pushes each file into an Azure Blob storage container and returns the url to each file.
The function itself works perfectly when I do a single file or multiple file post through Postman using the 'multipart/form-data' header. However when I try to post a file through an xUnit test, I get the following error:
System.IO.InvalidDataException : Multipart body length limit 16384 exceeded.
I have searched high and low for a solution, tried different things, namely;
- Replicating the request object to be as close as possible to Postmans request.
- Playing around with the 'boundary' in the header.
- Setting 'RequestFormLimits' on the function.
None of these have helped so far.
The details are the project are as follows:
Azure Function v3: targeting .netcoreapp3.1
ANSWERAnswered 2021-May-16 at 09:00
It took me a 50km bike ride and a good nights sleep but I finally figured this one out :-).
The Azure function (AF) accepts an HttpRequest object as a parameter with the name of 'req' i.e.
public async Task Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "images")] HttpRequest req)
The hierarchy of the files object in the HttpRequest object (along with the parameter names) is as follows:
- HttpRequest -> req
- FormCollection -> Form
- FormFileCollection -> Files
- FormCollection -> Form
This is what the AF accepts and one would access the files collection by using req.Form.Files
In my test case, instead of posting a FormCollection object, I was trying to post a Stream of a file to the Azure Function.
I recently needed to Generate Email Confirmation Token for my .net core 5 app, and while researching I found out I need to register "
AddIdentity" at startup.
ANSWERAnswered 2021-May-09 at 20:27
Here's the source code.
Basically it adds default Stores: UserStore and RoleStore. If you don't use it you have to provide Stores yourself with AddUserStore and AddRoleStore.
I'm working through the example provided here:
- Use cookie authentication without ASP.NET Core Identity
And I'm trying to implement something similar in my own app. Much of what the sample app does works, as replicated in my app, but there is one critical functionality that does not.
In this sample app, there is a "Contact (Authentication Required)" link, that when clicked loads the "/Contact" page - if the user is logged in.
If the user is not logged in, the "Contact (Authentication Required)" link still has its href= set to "/Contact", but when you click on it you end up in the "/Account/Login" controller, with ReturnUrl set to "/Contact".
The "Home" link directs to Index.cshtml, and does not redirect to /Account/Login " if the user is not logged in.
Which is all pretty ordinary, except ... I cannot find where the redirect to /Account/Login is configured, and I cannot determine why we're redirecting on one page but not the other.
What is it that causes Contact to redirect to Login and Home to not, and where do I configure that it's Account/Login that I want to redirect to?
Rakib's comment pointed me to a YouTube video, and an earlier video in the same series gave me a hint on one of my problems.
The sample app, in ConfigureServices(), has:...
ANSWERAnswered 2021-Apr-08 at 20:28
What is it that causes Contact to redirect to Login and Home to not?
- If the page or controller is configured to allow anonymous it will not redirect to login
I have entries in MySQL Database but i am not able to implement jquery datatable plugin on database for showing that table in browser as jquery plugin datatable (server side processing). How can i implement it ?
Here are files and folders.
ANSWERAnswered 2021-Jan-18 at 07:53
Here is a demo to show Courses with DataTable: Controller(I use fake data to test):
No vulnerabilities reported
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page