.net User Secrets not working on Windows 10 - c#

I'm running into a problem where UserSecrets returns my secret on Mac, but not windows. I followed https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?tabs=visual-studio
On windows, when I try to get the secret: Configuration["ConnectionStrings:Production"] it returns null.
I have the secrets.json file saved at C:\Users\username\AppData\Roaming\Microsoft\UserSecrets\<userSecretsId>
I can't figure out why it won't work on Windows, while it works perfectly on Mac. Any help is greatly appreciated.
It might be worth noting this is on a Windows Server
I'm wondering now if %AppData% is different in the context of IIS?
I think this thread is the right direction but none of the solutions work for me

The IIS ApplicationPoolIdentity should have it's own user profile folder, which is not the same as your user folder.
To find it, navigate to C:\Users, and you should see folders named for the application pools, so for an App Pool named ".NET v4.5" there should be a user folder called ".NET v4.5". Under that folder you should be able to follow the rest of your breadcrumb through the AppData folder and create the "\AppData\Roaming\Microsoft\UserSecrets" folder if it doesn't exist.
If that doesn't work or if you don't see user folders for the Application Pools, open up IIS Manager, select the Application Pool you're running under, then open Advanced Settings (link on the right hand side)
After opening the Advanced Settings, scroll down to the Process Model section and you should see a configuration for "Load User Profile", and make sure the value is set to True. Default is true in Windows 10, but depending on how you've done config prior versions of Windows defaulted to False which would make the secrets not available.

Related

Create directory (on network driver) throw an error wile runing on IIS

I am using asp.net mvc 5 with c#. The app needs to create a folder in the server when certain action occur.
The folder has to be created in one network drive. All this works properly when the app is running in visual studio, however, doesn't work on IIS.
My guess is that the IIS does not have enough permissions, so i try to change the app pool identity, but the result wat the same.
Edited
One thing that could not help is that the network drive was created in the software in the server (QNAP server), not in windows.
How can i make IIS behave like visual studio ?
How about you create a virtual directory that maps to the nas share folder. Here are a few steps.
In IIS on your site right click and do "Add Virtual Directory"
In the dialog that pops up give some alias name and in the physical path enter the location to share folder.
Click the connect as button. In the pop up select specific user and then enter the credentials.
Now from your code you access virtual directory.
Hope that helps.

MVC Shows Directory Listing Not Loading Application

I have a project that for some reason isn't loading the project, but just is showing me the directory listings. I have even tried running it in local IIS to see if it makes a difference and it doesn't
Things I have tried
modules runAllManagedModulesForAllRequests="true"
remove and reinstall IIS from manage windows applications in control panel
If I create a template MVC project in visual studio and run it , it runs fine so that makes me think its not my configruation. Other uses with the same project and web config are having no problem getting the site to load.
Also if I try and goto /Home/Index I get a 404 error. Not sure if that helps in any way
Any other ideas I may be missing here
IIS 10 on Windows 10
Check that IIS is installed and features you require are enabled
Register Asp.Net in Windows 10 for the Framework version you use.
dism /online /enable-feature /all /featurename:IIS-ASPNET45
Remove read-only tick and grant IIS with permissions on the folder your application is deployed.
You need to go over your IIS configurations again, do re-check whether you have the “Default Document” set for your website in IIS Manager.
Also, if you’re running directly via Visual Studio, check whether you have selected the relevant “Project” as the “Startup Project” for the Solution (visit https://msdn.microsoft.com/en-us/library/a1awth7y.aspx).
If the above fail, do recheck the IIS Permission for the particular project (visit https://support.microsoft.com/en-us/help/313075/how-to-configure-web-server-permissions-for-web-content-in-iis)
Lastly as mentioned above, do un-check the "Read Only" Flag if its there.
Do share your feedback and let me know if your problem still persists.

how to host asp.net app locally

I have a ASP.NET website, developed by a freelancer. After developing the website, he directly uploaded the website to my domain. Now, how can I host that website locally on my computer?
I dont have any experience in ASP.NET, however I do know HTML5 and CSS3. Looking at the files, I noticed they are all .cshtml files.
Any help would be great. I have the login credentials of Plesk.
Thanks in advance
You need to use IIS.
To do this, assuming you are on Windows, you need to enable it under the 'Windows Features' setting screen as below:
Check the 'World Wide Web Services' option, and also 'IIS Management Console' under the 'Web Management Tools' section.
After it installs, you will have a new program in your start menu, called 'Internet Information Services (IIS) Manager'.
This is where you setup and configure any local websites. There will already be a default website set up, which you can use, or you can create a new one by right clicking on 'Sites' in the tree on the left, and selecting 'Add Website':
Assuming you just use the default, you will need to copy your application to C:\inetpub\wwwroot\. You will then be able to access this by pointing your browser to http:\\localhost or http:\\127.0.0.1.
Assuming you are working with Windows, you will need to install an IIS on your machine. IIS is a part of Window's features, you can try installing it under:
Control Panel > Program and features > Turn windows features On / Off > Internet Information Services.
In some versions of windows, IIS is not available. In that case, you will need to download IISExpress.
After that - Configure a new website under your IIS, and point the website to the directory in your computer which has the project.
Read more here:
Installing IIS
Setting up a website

How to find out which user web app is running as?

I'm using HttpPostedFile.SaveAs() in a Web API app. It fails to save with an access denied error if the file already exist.
From this post HttpPostedFileBase.SaveAs method question, that should not be the case. If I manually delete the file, all is well.
Is this issue related to permissions?
When I look in Explorer at the users who have permissions on this folder, there are four. Only my user doesn't have write permissions. I don't think that is the issue because otherwise, I wouldn't be able to write at all correct?
This is running on my dev machine.
It depends if the web app is running under IIS or IIS Express.
If your'e running from visual studio by default it on IIS Express, in that case the user is the user which ran Visual Studio (you). Be sure to run VS as administrator.
Under IIS the user is determand by the user running the Application pool which the app is attached to. By default a new special user is created for you which be named after the app-pool. You may change it at:
IIS-> Application Pool -> Right click the correct apppool -> advanced -> change the identity.
The easyest way to find out the actual user is to look at windows Task Manager (ctrl+shift+esc), go to Details, look for w3wp.exe and look at the username.

WebApplication works fine on IIS Express but it doesn't on Local IIS

I have a problem with my web application. I develop using VS 2013 (run as Administrator) and Windows 8.
When I debug using IIS Express - everything works fine, without any errors (I run VS as Administrator). When I change project properties to use Local IIS (it's installed) - I cannot use external library which is placed in GAC (Microsoft.FlightSimulator.SimConnect). Also I run VS as Administrator.
Thrown error: "HRESULT E_FAIL has been returned from a call to a COM component" - this says nothing to me. This is thrown during creating new SimConnect object:
var simconnect = new SimConnect(...)
OFC, to use SimConnect, firstly Microsoft Flight Simulator should be launched (and it's started). This was proposed reason of the problem which I found in the Internet - second one was granting permissions (described below).
Details:
I have two projects in solution: library project (which is used to connect to the FSX) and web project (MVC - to present the results).
1) I tried to move whole library project content to the MVC project - nothing.
2) I used IIS manager to publish my website (with the seperate AppPool) - result the same as for Local IIS.
3) I granted permissions to the folder (where projects are placed) for my own AppPool and also for IUSR, IIS_IUSR and DefaultAppPool - full access. And nothing.
4) I ran FSX as Administrator - also nothing :/
I found the workaround: I moved the library project to the another project - console application where I used HttpSelfHostConfiguration to host that. And later, I call this api from the main project (MVC). For this solution everything works fine (I tested for Local IIS [debugging] and also for IIS Manager). I have to only run the Host Api project as Administrator.
I'm very curious what is the reason of the exception. And additionally: how to resolve that :)
It seems like the problem with the permissions - but I granted to the every used AppPool.
Can be the reason lack of permissions for dll in GAC? I don't think so, but I have no idea what to do. If yes, how to grant permissions for dll in GAC (or how to copy that)?
#Krzyrok, Had the same issue recently on my one of my projects where I used external libraries. After following endless crumbs I got it resolved. Change your application pool identity from "ApplicationPoolIdentity" to "LocalSystem". I also changed the sites Anonymous Authentication to "Application pool identity" from the specified IUSR but tested it and it can be left on IUSR. I also granted permissions to the folder for IUSR and IIS_IUSR.
If someone comes across this problem, it is possible that the problem is that you have not configured SSL for your localhost site. The site might be trying to communicate via https port 443 and it cannot find the site there. The site may be hosted only on the unsecure http port. To solve this problem,
Go to IIS Manager
Right Click on the Website
Click on Bindings on the right
Click on Add
Select https
Select the IIS Express certificate
Click OK
I was using the physical path of the \bin folder as the basic settings physical path of the web site in IIS. I forgot I had to publish the web service and use the publish path as the basic settings physical path of the IIS website.

Categories

Resources