Posts

Showing posts with the label asp.net-core

ITelemetryProcessor breaks dependency tracking

Image
Clash Royale CLAN TAG #URR8PPP ITelemetryProcessor breaks dependency tracking I have set up a custom ITelemetryProcessor for my .NET Core 2.1 Web API. I do not want HTTP status codes 400 or 401 to be displayed as error in Application Insights. The following class does this, but as soon as I use it SQL and HTTP client dependency tracking will no longer work: ApplicationInsights400IsOkProcessor public class ApplicationInsights400IsOkProcessor : ITelemetryProcessor { private ITelemetryProcessor Next { get; set; } /// <summary> /// Link processors to each other in a chain. /// </summary> /// <param name="next"></param> public ApplicationInsights400IsOkProcessor(ITelemetryProcessor next) { this.Next = next; } /// <summary> /// API Aufrufe mit Rückgabecode 400 und 401 sind keine Fehler /// </summary> /// <param name="item">Telemetry zum Verarbeiten</param> public void P...

ASP.NET Core Web API to connection Oracle 11 g database using ODP ORM

Image
Clash Royale CLAN TAG #URR8PPP ASP.NET Core Web API to connection Oracle 11 g database using ODP ORM I am new in .net core platform then i have no idea to connect oracle db to ASP .net WEB API. how to create ASP.NET Core Web API to get the data from an Oracle database using ODP ORM.? It's Code First Approach !! 1 Answer 1 you should consider to use NHibernate: Hibernate is a mature, open source object-relational mapper for the .NET framework. It's actively developed, fully featured and used in thousands of successful projects. It's built on top of ADO.NET and the current version is NHibernate 4.0.4. tutorialpoint NHibernate By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

ASP.NET Core 2.0 - HTTP Error 502.5 Process Failure with IIS

Image
Clash Royale CLAN TAG #URR8PPP ASP.NET Core 2.0 - HTTP Error 502.5 Process Failure with IIS I am trying to set up a new version of my application on a server but when I try to access to the web site, I get a HTTP error (502.5 - Process Failure). The service is started and when I check the connection, I don't have any warning. The stdout log : stdout Expression: [Recursive resource lookup bug] Description: Infinite recursion during resource lookup within System.Private.CoreLib. This may be a bug in System.Private.CoreLib, or potentially in certain extensibility points such as assembly resolve events or CultureInfo names. Resource name: ArgumentNull_Generic If I try the dotnet cmd to launch the exe : >dotnet Maquetteur.Web.exe Failed to load the dll from [C:tempMaquetteurWinServer2012_newhostpolicy.dll], HRESULT: 0x7BF030 An error occurred while loading required library hostpolicy.dll from [C:tempMaquetteurWinServer2012_new] In my csproj : csproj <PropertyGroup> <Ta...

Specify equality comparer for model binding to collection types

Image
Clash Royale CLAN TAG #URR8PPP Specify equality comparer for model binding to collection types I have an API where you can specify a list of names to get. Duplicate names are not allowed and if two names differ only by casing then they are considered duplicates. GET /api/people?names=john&names=alice In my own .NET code I would gather all these names in a HashSet with a custom equality comparer. HashSet var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase); But I don't think ASP.NET Core model binding is flexible enough for that. // GET /api/people?names=john&names=JOHN [HttpGet("api/people")] public GetPeople([FromQuery] HashSet<string> names) { // this works but names contains both john and JOHN } What do I have to change so that the names set only contains john and not JOHN? names 2 Answers 2 You can use a List<string> in the method heade...

kestrel-hellomvc.service: Failed at step USER spawning /usr/bin/dotnet: No such process

Image
Clash Royale CLAN TAG #URR8PPP kestrel-hellomvc.service: Failed at step USER spawning /usr/bin/dotnet: No such process I was following the tutorial https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction on publish asp.net core project on nginx the previous steps all seem successfully, but while systemctl start kestrel-hellomvc.service systemctl status kestrel-hellomvc.service I got kestrel-hellomvc.service - Example .NET Web API Application running on Ubuntu Loaded: loaded (/etc/systemd/system/kestrel-hellomvc.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2017-04-24 03:12:42 UTC; 8s ago Process: 4285 ExecStart=/usr/bin/dotnet /home/84999/Demo4/Demo4.dll (code=exited, status=217/USER) Main PID: 4285 (code=exited, status=217/USER) Apr 24 03:12:42 instance-5 systemd[1]: Started Example .NET Web API Application running on Ubuntu. Apr 24 03:12:42 instance-5 systemd[4285]: kestrel-hellomvc.service: Failed at step USER spawning /usr/bi...

ASP.NET Core app only works as root

Image
Clash Royale CLAN TAG #URR8PPP ASP.NET Core app only works as root I just updated all the Microsoft packages on my ASP.NET core app to the latest 2.1 versions (as well as updated the SDK to 2.1.4 on my CentOS server) and pushed the code to the server. I rebuilt the code server-side and deployed it to the web root. I can't get the server to respond now unless it runs as root. When attempting to connect through the Apache proxy, I get a 502 Proxy Error and when I attempt to connect directly to the SSL port the Kestrel server is listening on, I get ERR_CONNECTION_CLOSED in Chrome. 502 Proxy Error ERR_CONNECTION_CLOSED If I run the site manually as root user ( dotnet WebsiteMainDll.dll ) it works fine. If I run it manually as the user it should run as ( sudo -u siteuser dotnet WebsiteMainDll.dll ), it doesn't work. dotnet WebsiteMainDll.dll sudo -u siteuser dotnet WebsiteMainDll.dll There are no errors shown in the console. It just shows Now listening on https://0.0.0.0:44313 an...

Blazor .NET Core: How can I set the connection string?

Image
Clash Royale CLAN TAG #URR8PPP Blazor .NET Core: How can I set the connection string? I am trying to use Blazor's CRUD functions and following some article to do this. In the article, there is a part that I should put my connection in context file, but it doesn't say how to set the connection string. I put this code line in launchSettings.json: { "ConnectionStrings": { "UserDatabase": "Server=DESKTOP-2K2A6GN;Database=Assignment4;Trusted_Connection=True;" }, "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:56244/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT...

.NET Core 2.1 - dotnet/exe on build, packages are missing

Image
Clash Royale CLAN TAG #URR8PPP .NET Core 2.1 - dotnet/exe on build, packages are missing I've been developing on one machine and recently tried to install my application on another PC. I think I've deduced to to the nuget packages not being found since in .NET Core, nuget puts the packages in the local 'Users' folder path. I initially added the <RunTimeIdentifier> tag to create an exe (which worked on my developer machine). When running the exe on a different machine, the console window will flash very quickly and application stops with no error output (even in Event Viewer). <RunTimeIdentifier> I also added this tag <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest in the *.csproj which did not make a difference. So I tried running dotnet project.dll which gave me this error on the other machine. dotnet project.dll An assembly s...

Why aren't ASP.NET MVC tag helpers creating the correct link?

Image
Clash Royale CLAN TAG #URR8PPP Why aren't ASP.NET MVC tag helpers creating the correct link? I have an asp.net core MVC project with scaffolded Identity, and the tag helpers in the _LoginPartial view are acting wonky. In the Razor view, the link looks like this and don't navigate to any page or view. <a class="nav-link" asp-area="Identity" asp-page="/Account/Manage/Index">Manage Account</a> but for some reason it's being rendered like this (taken from the dev console in chrome): href="/?area=Identity&page=%2FAccount%2FManage%2FIndex" I don't know why this is happening and I can't figure out how to get it to render properly and allow navigation to the correct page. You should be using asp-controller=".." and asp-action="..." – Stephen Muecke 2 days ago ...

ASPNET Core MVC - Form to GET url

Image
Clash Royale CLAN TAG #URR8PPP ASPNET Core MVC - Form to GET url Good evening, I have a simple question that I can't seem to find answer to anywhere. I have a controller method with HttpGet route set like this: [HttpGet("tools/browse/{table}/{row}/{offset}")] My question is simple and I know that a lot of people would be interested in the answer aswell. How does one use such form: <form action="/tools/browse/{table}/{row}/{offset}" method="get"> <input type="text" name="table" value="" /> <input type="number" name="row" value="" /> <input type="number" name="offset" value="" /> <input type="submit" /> </form> ..so that {table}, {row} and {offset} contain values from the form itself? I know that the workaround would be using post or simply parsing the form data within function - b...

The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor'

Image
Clash Royale CLAN TAG #URR8PPP The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' Trying to teach myself some new tools, but I've managed to break my project. The solution is about a day old and consists of two projects. One is the application (created using the Visual Studio .NET Core 2.1 SDK + React Template ), and the other is the data layer (which is just a Models folder). Models The data layer was implemented today, and that's when things got rocky. I don't want to point the finger there immediately, because it could've happened with some other changes I was making at the same time. One or more compilation references are missing. Ensure that your project is referencing 'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false. The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' (are you missi...

Schema, table and column names processing via custom migration class with Fluent Migrator

Image
Clash Royale CLAN TAG #URR8PPP Schema, table and column names processing via custom migration class with Fluent Migrator I'm writing a migration tool for modular applications which are intended to use internal modules, each with its own set of migrations. Our applications are all based on dotnet core, may use different dbms and can use different conventions: each module in its own schema or not, custom table prefix per module, upper or lower case table names, etc. Thus these conventions need to be told by the application itself while needing to write only once each migration in each module. I'd like not to have to call a method call each time we insert a column name, table name, etc, for the developer not to have to have all this stuff in mind. I started to reimplement each expression builder, but I feel it's very wrong and error-prone. I also made a custom generic Migration class, inheriting Migration and having a naming convention interface as a generic type (which as thr...

Making React APP with ASP.NET Core API Server

Image
Clash Royale CLAN TAG #URR8PPP Making React APP with ASP.NET Core API Server I have a situation and I'm trying to make React app using ASP.NET Core API Server. First, I made a template which Visual Studio provide and I couldn't understand serveral parts. I have experiencies with ASP.NET Core MVC, React + NodeJS, Vue + NodeJS etc, only except TypeScript . But! the ASP.NET React template has only TypeScript examples and settings. Because of those reasons(plus not familiar with React Template), I want to konw and try the step by step process of Making React APP(consists of .jsx) with ASP.NET Core API Server template for SSR(Server Side Rendering) . Is there any advice or reference for it? I can not find it... I just spent times... thanks By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the we...

Modify site content and render it in browser

Image
Clash Royale CLAN TAG #URR8PPP Modify site content and render it in browser I am writing a proxy for some site using ASP.NET Core 2.0. My proxy works fine if all it does is just re-translating HttpResponseMessage to the browser. My proxy based on this example. But I need to make some changes site content, for instance, some of the href contains an absolute reference. So when I click them from my proxy, I get to the original site, and it is a problem. HttpResponseMessage When I tried to get site HTML as a string, I got only special characters. After some search, I find this solution. It fits for my case well and I successfully get site content as a string, which starts with "<!DOCTYPE html>..." . After changes are done I need to send this string to my browser, and here I have a problem. I work with the HttpResponseMessage the following way: "<!DOCTYPE html>..." HttpResponseMessage using (var responseStream = await responseMessage.Content.ReadAsStreamAsy...

How to validate string parameter with ValidationAttribute

How to validate string parameter with ValidationAttribute how can i validate a string parameter in a HttpGet method using ValidationAttribute: public class LocaleAttribute : ValidationAttribute { public LocaleAttribute() : base(UserInteractionErrors.InvalidLocale) { } public override bool IsValid(object value) { if (value is string && CultureInfo.GetCultures(CultureTypes.AllCultures).Any(c => string.Equals(c.Name, (string)value, StringComparison.OrdinalIgnoreCase))) return true; else return false; } } [ApiController] public class ConsentController : Controller { [HttpGet] [Route("api/get/{locale}")] public async Task<IActionResult> Get([Locale] string locale) { something } } Any ideeas? What doesn't work with the posted code? – Camilo Terevinto 4 mins ago ...

Get the less-sold items with LINQ

Get the less-sold items with LINQ I have 2 objects (Order and Product) and a third (OrderDetail) that will be used as "navigation" between Products and Orders. I'm trying to build a view that will show the less-sold products. For that I am "querying" the object OrderDetail and saving the result in a view model to later on be used in the view. Model: public class Product { public int ProductID { get; set; } public string CodProduct { get; set; } public string Nome { get; set; } (...) public ICollection<OrderDetail> OrderDetails { get; set; } } public class Order { public int OrderID { get; set; } (...) [BindNever] public ICollection<OrderDetail> OrderDetails { get; set; } } public class OrderDetail { public int OrderDetailId { get; set; } public int OrderId { get; set; } public int ProductID { get; set; } public int Quantity { get; set; } public decimal UnitPrice { get; set; } public virtual Product Product { get; set; } ...