NetCore API Impersonate - asp.net-core

I have a Web and an API NetCore Application running in a machine that I have access by VPN.
There, in IIS, I've configured both applications in IIS: The Web and the API. They are running well.
At the API, I've tryied to open the file from a network path:
\10.50.20.24\g$\Buffer\821003\003\22\34\821003003223428.WAV
In my code, when I try to verify if the file exists, using System.IO.File, to after move it, I received a message saying that the file doesn't exists.
"file was not found"
But the file exists, and the file is there when I try to access it from Windows Explorer.
In the IIS, I've configured the same user to run the application, in the Identity of the application pool.
I've tried lots of things to try to access the file, unsuccessfully.
Do you think this is related to Impersonation? How could I implement Impersonation in Asp.Net Core API 3.1 ?

Related

Could not load file after another project updated package versions

We have 2 projects hosted on IIS: Blazor WebAssembly site and authorization web service.
Web service is hosted on Default Web Site, Blazor project as a separate site. Each has it's own app pool ('No managed code'). Both are .NET6 using EF Core. They do not reference each other.
Recently I updated packages in Blazor project to latest versions. After publishing that change our web serivce started throwing:
An unhandled exception has occurred while executing the request.
System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Abstractions, Version=6.0.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.EntityFrameworkCore.Abstractions, Version=6.0.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder..cctor()
EntityFrameworkCore libraries on that web serivce are of version 6.0.5. Our Blazor site was moved to 6.0.6. How can one affect the other?
They are both published by Jenkins as self-contained without trimming, then copied to server.
Web service does not reference Microsoft.EntityFrameworkCore.Abstractions directly, but I can see it down the line of package refences for EF Core.
I can see the relevant library in the physical folder on server, it's of expected version 6.0.5.
Still, web server throws on any GET, with Swagger or via the Blazor site.
Tried so far:
Add rights for IIS_IUSRS for site and service folders
Changing app pool identity for web service
Add rights for app pool specific users for site and service folders
Enabling 32-bit app setting in IIS, it is not compatible with our apps
Checked that ASPNET user has rights to Temp folder just in case
The issue still occurs, on some days it all works without problems.
There are many reasons for this error, you can try below methods:
Restart the server to reload everything again, check if site works.
Change 'Enable 32-bit application' from false to true in the advanced settings of the application pool.
Change the identity of the AppPool that your app is using to NetworkService.
IIS > Application Pools > Select current app pool > Advance Settings > Identity.
Grant IIS_IUSRS full access to the Microsoft.EntityFrameworkCore.Abstractions.
Setting hosting model as OutOfProcess for the web service finally fixed the issue. Other solutions did not provide any lasting results.
It can be set in web.config:
<aspNetCore ... hostingModel="outofprocess">

ClickOnce, Azure, and ASP.NET Core

I have an ASP.NET Core application published to Azure. It contains companion application published using ClickOnce.
When I look at the web server's console, I see all of the necessary ClickOnce files. And I can launch the application using http://mysite.azurewebsites.net/tools/MyApp.application as expected.
But if I click on http://mysite.azurewebsites.net/tools/setup.exe it fails with a 404 error.
I'm assuming that the ASP.NET application is preventing "setup.exe" from being exposed, but I don't know how to alter that configuration.

Referencing a Published WCF Service

I have followed "Walkthrough: Creating and Accessing WCF Services" from http://msdn.microsoft.com/en-us/library/bb386386.aspx to create a WCF Service Library. I tested it in WCF Test Client. Then in another desktop application (let's call it A) that eventually I would like to use this WCF I added the Service Reference that WCF Test Client gives
http://localhost:8733/...
and that worked too.
Now, I am in the process of publishing and using the published version's service reference. Here is what I did, I published the WCF Service Library by
right-clicking the solution
Choosing Publish
clicking ...
Choosing File System and typing
\mywebaddress.example.com\wwwroot\myWCFService
Looks like the publish is successful, because by navigating to
\\mywebaddress.example.com\wwwroot\myWCFService
in a file browser, I see that Web.config, .svc and bin folder are created.
Now, I am trying to refer to this published version from my desktop application A. I am not certain what options I'm supposed to choose
Here is what I have tried:
Choose Add Service Reference in the desktop application A,
I tried
\mywebaddress.example.com\wwwroot\myWCFService
in the Address field of Add Service Reference, Pressed Go and received the error An error (Details) occurred while attempting to find services at
\\mywebaddress.example.com\wwwroot\myWCFService.
When clicking on Details, I get There was an error downloading
\\mywebaddress.example.com\wwwroot\myWCFService
Access to the path
\\mywebaddress.example.com\wwwroot\myWCFService
is denied.
If the service is defined in the current solution, try building the solution and adding the service reference again.
Alternatively, I tried Advanced option from Add Service Reference and from there Add Web Reference... and in the URL field typed
http://www.example.com/myWCFService/
then when pressing the arrow button I get 401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied. and in the Web services found at this URL: Value cannot be null. Parameter name: discoveryError & mexError.
Th latter error was when in the IIS setting I had Anonymous Authentication Disabled. After enabling Anonymous Authentication the error becomes:
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
Web services found at this URL: There was an error downloading
http://www.example.com/wcfservice/_vti_bin/ListData.svc/$metadata
The request failed with HTTP status 404: Not Found.
When I just now published a WCF Service Library project with Visual Studio 2013, I was offered the options for file system, Local IIS, and FTP Site. When I choose "Local IIS", it shows me both IIS Express and my local full IIS.
I just published to IIS by selecting "Default Web Site" and clicking the "Create Web Application" button in the tooolbar. I named the application, clicked "Open", then clicked "Publish" on the main publish dialog.
This published a bin folder with the service DLL and other libraries it needed, a web.config, and a .svc file. I was able to browse to the .svc file with no problem. I was even able to add it as a service reference to another project.
If you are always going to host your services in IIS, and if you don't need to keep a clean separation of layers (perhaps you're only writing a few, simple services), then I recommend you use the "WCF Service Application" template instead. This creates a Web project in which to host the services, as well as the .svc and .cs files necessary for the services themselves. That's more like the only option that was available for ASMX web services.

ASP.NET WebAPI deployed to IIS: Access to web.config denied (IIS searches in wrong path)

I have an ASP.NET MVC/WebAPI mixed project which runs just fine in the VS2012 development server. It has a standard MVC {controller}/{action}/{id} route, as well as an additional WebAPI route api/{controller}/{id}. Requests which start with /api/... are directed to WebAPI, the others to normal MVC.
When I deploy it to the local IIS, the normal MVC routes are working. However, /api calls to WebAPI are resulting in the exception
Access to the path 'C:\inetpub\wwwroot\myapp\web.config' is denied.
Then I tried to set the proper security permissions on the inetpub folder and its subfolders. This didn't help anything, and because the normal MVC requests are working, I don't suspect the problem to be security-related.
Then I started Sysinternals Process Monitor to see what w3wp.exe is doing during the request. As it turns out, IIS looks for web.config here:
C:\inetpub\wwwroot\myapp\api\web.config
C:\inetpub\wwwroot\myapp\api\mycontroller\web.config
Of course, there is no web.config there.
How can I set up IIS to recognize both routes?
I do not believe this is a problem with your routing. the problem is the permissions given to IIS I run into this error from time to time. Depending on the app pool identity you are running under you need to provide permissions to that entity. Here is a link to a very thorough explanation
IIS AppPoolIdentity and file system write access permissions
Basically right click your project folder, go to properties, click the security tab and and you will see Group or user names. These are the allowed entities to perform read and/or write actions to that directory. Click Edit then Add; from here you will then "Enter the object names to select" typically IIS follows under IIS_IUSRS again this depends on your app pool configuration from here you should move on from the error mentioned!
I hope this helps!

Basic WCF service gets "Invalid application path" on Test Settings

Caveats: It's been six years since I deployed a few web services and my knowledge of IIS is slim.
Background: I'm trying to host a WCF 4.0 service under IIS on my local box (Win7 64-bit) but keep getting "Invalid application path" when attempting to Test Connection. So I've gone vanilla and
created and started a new WCF Application (via the .NET template) (so responds under Cassini);
added a new application under the Default Web Site;
assinged it to the DefaultAppPool;
set the path to the folder where my .svc file resides; and
verified that the DefaultAppPool is targeting the 4.0 framework
Also, when I test the default web site settings pass-through authentication succeeds but an Authorization warning indicates "Cannot verify access to path (C:\inetpub\wwwroot).
Problem: When I pull up the apps basic settings and click "Test Settings..." I get an error "There was an error while performing this operation. Details: Invalid application path"
Does anyone have suggestions as to how to get the settings to check out correctly?
Thanks.