windows authentication in aspnet core app while debugging - debugging

I am trying to develop an application that uses AD for determining user access. I have implemented the windows authentication and it works when I deploy the app to IIS, but I want to use it while development time for debugging purposes. I have already configured the launchsettings.json file to have below.
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:5001",
"sslPort": 5002
}
}
Why am I not able to get this working. Is there something else that I am missing?

You said IIS-Express - do you have Web.config ?
<system.webServer>
[…]
<security>
<authentication>
<anonymousAuthentication enabled="false"/>
<windowsAuthentication enabled="true"/>
</authentication>
</security>
</system.webServer>

Right-click on the project and in the debug settings, changed the launch options to IIS. After that I got an error saying dotnet.exe not found. That error lead me to Unable to start process dotnet.exe, which says in IIS, web.config files are useless for aspnetcore projects. I then deleted the web.config file and it worked. I was able to get the user details into the IHttpContextAccessor.

Related

Getting error happens when the section is locked at a parent level in VIS2019 in windows 10 with IIS Express

Im using this in my web.config in my VS2019 project with IIS express on windows 10.
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
But I get this error
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
I looked at the internet to try different things, but none seem to work.
https://digitaldrummerj.me/iis-express-windows-authentication/
https://mpituley.wordpress.com/2016/10/04/http-error-500-19-in-the-iis-express/
Config Error: This configuration section cannot be used at this path
Config Error: This configuration section cannot be used at this path
Config Error: This configuration section cannot be used at this path
IIS Config Error - This configuration section cannot be used at this path
I've modified the files
C:\Users\me\Documents\project\.vs\config\applicationhost.config
C:\Users\me\Documents\IISExpress\config\applicationhost.config
I'm not sure what else to try.
Does anyone know?
Figured it out, there was another file I had to edit
C:\Users\me\Documents\project\.vs\project\config\applicationhost.config

How do I setup tnsnames.ora in asp.net core web application?

I have a small asp.net core 2.2 app that should access an oracle db; I'm using NuGet Oracle.ManagedDataAccess.Core (2.18.6), and it just works on my machine.
When I deploy it to the windows server with IIS, I place a tnsnames.ora file in app's directory and again it just works.
Now I want to use a shared tnsnames.ora file. I have tried web.config like following (recipy from StackOverflow/Google answers to similar questions).
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</configSections>
<!-- skipping app stuff -->
<oracle.manageddataaccess.client>
<version number="*">
<settings>
<setting name="tns_admin" value="F:\path\to\tnsadmin\folder" />
</settings>
</version>
</oracle.manageddataaccess.client>
</configuration>
Unfortunately, this doesn't work (and since the Core version of Oracle.ManagedDataAccess.dll doesn't have an ODPMSectionHandler class it isn't a big surprise).
So, is there a way to have a shared tnsnames.ora file with odp.net core?
(PS imo we need the odp.net-core tag)
UPDATE
One need to ensure the w3wp.exe can actually access the files.
Setting system environment variable TNS_ADMIN is a possible solution. It'll suffice in this particular case, but I'm still curious about how to configure it via web.config.
ODP.NET Core does not support config files like standard ODP.NET does. You will need to use the Configuration APIs:
https://docs.oracle.com/en/database/oracle/oracle-data-access-components/18.3/odpnt/InstallCoreConfiguration.html
With Oracle.ManagedDataAccess you don't need to use a tnsnames.ora file. In fact, you don't need an Oracle client installed on the web server. Use startup.cs.
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFrameworkOracle()
.AddDbContext<OracleDbContext>(builder => builder.UseOracle(Configuration["Data:OracleDbContext"]),ServiceLifetime.Scoped)
.AddDbContext<AppsDbContext>(option => option.UseOracle(Configuration["Data:AppsDbConnection:ConnectionString"]), ServiceLifetime.Scoped);
}
apsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"Data": {
"OracleDbContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zzz)(PORT=1521))(CONNECT_DATA=(zzzz)));User Id=zzz;Password=zzz;" },
"AppsDbContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=yyyy)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=yyyy)));User Id=yyyy;Password=yyyy;" }
}
}
I just ran into the same issue, strangely enough setting env variables system wide didn't seem to work. I had to configure it in the web.config itself for it to find the TNS_ADMIN, like so:
<aspNetCore ...>
<environmentVariables>
<environmentVariable name="TNS_ADMIN" value="C:\Oracle\product\11.2.0\client_1\network\admin" />
</environmentVariables>
</aspNetCore>

Visual Studio browser link is grayed out

I'm using visual studio 2013, and web essentials 1.1.
I'm trying to use browser link, but the button for it is greyed out in Visual Studio.
Any idea how I can enable it?
Do you have this setting in your Web.config file
<appSettings>
<add key="vs:EnableBrowserLink" value="false"/>
</appSettings>
or debug to false?
<system.web>
<compilation debug="false" targetFramework="4.5" />
</system.web>
source: http://www.asp.net/visual-studio/overview/2013/using-browser-link
Check if the solution root has a file named WebEssentials-Settings.json
From that file, you'll see something like this:
{
"BrowserLink": {
"CssIgnorePatterns": "bootstrap*; reset.css; normalize.css; jquery*; toastr*; foundation*; animate*; inuit*; elements*; ratchet*; hint*; flat-ui*; 960*; skeleton*",
"EnableMenu": true,
"EnablePixelPushing": true,
"ShowMenu": false
},
/* further settings down below */
}
Notice you have 2 settings. EnableMenu and ShowMenu. I had the same issue as you are having and I got ShowMenu: false while EnableMenu: true. I changed both to true, reopened the solution and it worked.

servicestack hello failed to load http handler

I am following the Hello Web Service tutorial on ServiceStack.net. I get the message below when trying to access the service:
Failed to load httpHandler type `ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack'
I am using xsp which I started in my working directory for the project with the default values (i.e.: port 8080). I edited the web.config in this directory as documented in the tutorial.
How does the service find the http handler? Using xsp on port 8080 will I be able to open the metadata page?
The web.config which is in the same directory as the app contains:
<configuration>
<!-- Required for MONO -->
<system.web>
<httpHandlers>
<add path="servicestack*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<!-- Required for IIS7 -->
<system.webServer>
<!-- ServiceStack: Required -->
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
As mentioned I'm working with Mono and xsp. I now realize that in my working directory, MonoDevelop not only created web.config but also a bin directory which contains all of the dlls that I created and referenced in my project.
Setting xsp root directory to the path containing the web.config and ./bin enabled the http handler to be found and allowed me to finally access my web service and
http://localhost:8080/ServiceStack/metadata
In this scenario I did not need my dlls to be in /bin but in the project's bin
I had also overlooked the call to HelloAppHost().Init()
Bit of a learning curve... but I'm looking forward to using ServiceStack.
Thank you #mythz and #Mr.Young
I think your configuration might be incorrect. You might have mixed up the configuration with the configuration for using ServiceStack with an existing web framework.
The basic configuration for hosting ServiceStack at the root (/) path without any other web frameworks is
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
Remove the servicestack* from the path and the IIS specific stuff. It's possible your running into the VERY uncool bug in Mono ASP.NET implementation of virtual paths, details here: https://groups.google.com/d/msg/servicestack/kzfS88RldIU/LsJ2jV9M2LIJ

Access web.config settings from iisnode?

If I add settings to my app's web.config file, is there an API to read the settings from my app or do I have to read the file using an XML library?
There is no special API that allows you read web.config into your node.js application running in iisnode. Having said that:
all key/value pairs from the appSettings section in web.config will be promoted to environment variables of the node.exe process, so you can access them using process.env,
as of iisnode v0.1.19, in addition to web.config, configuration settings can be specified in a iisnode.yml file; see http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html for details.
This example shows how promoted key/value pairs from the appSettings section in web.config are available as environment variables. In your web.config file:
<configuration>
<appSettings>
<add key="abc" value="test" />
</appSettings>
</configuration>
In your node application: console.log(process.env.abc); //--> test

Resources