Prevent ASP.NET Core application from using appsettings.json file - asp.net-core

I would like to tell to ASP.NET Core application that even if appsettings.json file is there - ignore it.

I would prefer to write this as a comment but I'm still a newby here so I cannot ask questions.
I would like to understand what is the specific problem you are facing right now.
In general the usage or not of the appsettings file depends on your application.
For example, if you create a Web API using default .NET template, you can see that the appsettings file only has some configuration for logging, which you can even delete and nothing happens. You can run the application anyway and it works.
So, coming back to your question, it dependes on what your application is doing. If you have a specific library that needs to read configuration from this file, then you'll need to research how to change that default value.
If you are reading from that file, then you could set value in code instead. (this is obvious but since you didn't provide any more context I don't know what you are struggling with)

Related

unsaved changes? FileSystemProvider in VS Code for the Web

This is incredibly niche, but in case somebody knows I'm wondering if it's possible to get that "unsaved" marker to show in VS Code for the Web . I'm writing an extension with a custom FileSystemProvider to communicate with a remote storage service. As multiple people may have access to these files this auto-save behaviour is not appropriate.
Turns out auto save is on by default. Had to add .vscode/settings.json in the FilesystemProvider. I'll edit this answer if I find another place to override this default.

How can I run Zend Framework code alongside legacy (non-ZF) code on the same server on the same HTTP port?

I have a large codebase that I am trying to eventually convert to Zend-Framework-powered stack.
I at times write new modules to where I have a choice:
keep writing using legacy routing/initialization/etc
somehow figure out how to use ZF for the new module only while the rest of the legacy code works "as before"
Is this possible?
How?
To give you an idea, code I have now uses proprietary multiple routing files, where everything in ZF goes through one single router file.
So legacy code is called like so i.e.:
http://legacy:80/index.php?route=product
May be similar to zend framework 2 in a subdirectory
Zend Middleware approach
I was able to follow https://docs.zendframework.com/zend-mvc/middleware/ and implement an IndexMiddleware class. I can see that IndexMiddleware::process() method is being called. But I am not certain how to go further, and how to engage my legacy web application to return data as before.
MiddlewareListener.
Legacy App - index.php
$module = filter($_GET['p']);
if (!empty($module))
$inc = 'portal/{$module}.php'; //prep a legacy module
require($inc); //run module
There are many solutions there... Depends on how much new code you have, and addresses you want.
Long story short, you could work at the server level (aliases, rewrite, etc), or at the PHP code level.
Something you could do is use the index.php from the Zend Skeleton for instance, and the default url routing through index.php. Then look at the application lifecycle, especially the route event. I believe that's a good point to add a listener that would dispatch the old application. You can find numbers of Listeners in the Zend MVC code to base your code on (look at the middleware one for instance).

Support for multiple environments in your windows store app

I have been working on a Windows Store app where I have to support multiple configuration parameters for my app. One of the parameters is the URL the app is talking to.
For example development environment, test, acceptance and finally production.
One of the things i'm currently thinking about is what is the most efficient way of supporting all these environments with the least effort. Because there isn't some kind of config file that we can change to update these parameters I came up with some ideas. I'm curious about other options that I might have not seen.
Here are the things I came up with:
1
Adding multiple configuration to the app and than using them in code to get the correct parameter like this:
private string webserviceUrl;
#if DEV
webserviceUrl = "devUrl";
#elif TEST
webserviceUrl = "testUrl";
#endif
2
With the approach in number 1 there are a few more options available like including a config xml file bases on the configuration, or fetching configuration settings from a webservice the first time the app is running.
3
Using a branch/merge strategy and update the config files in the branch. Advantage is that the code is clean and only contains the settings it needs for the build it's created for. And the package can be build by the build server. Disadvantage is that you need to branch/merge alot.
The last option feels like the most 'clean' solution to do this. Am I missing any options, or do you have experience with any of these methods? What would you prefer?
I think the assumption is that apps in the store will always point to production.
But, in saying that, I'm facing the same issue as we're side loading the application onto devices that we control, and not using the Windows Store at all.
To answer your question, I prefer option 1.
Option 2 and the xml/json config file seems like the best option though.
The webservice option probably won't work. What webservice URL do you use? And how will it work if you want some instances pointing to different environments as they will all be fetching the config from the same URL.
Another option you might want to consider would be options in the settings charm menu. For example, use radio buttons for the environments, and allow the user to configure which environment they want to target.
The issue would be locking it down in production for end users so that it isn't modifiable any more. Perhaps once "PROD" radio is selected, all the radio buttons are then hidden.
If you're deploying the application through side loading, then these settings could probably be configured during the install process.
I'd be interested to hear other opinions as well. This is also an old question, so I'd like to know what solution you decided on implementing.

MVC 4 Bundling URL instead of files

I think my title says everyting, I want to bundle a set of action urls which return JavaScriptResult instead of physical files, is this somehow possible?
Best regards
I do not think you will have to wait for new release of ASP.NET MVC.
WebOptimization library is a separate project - that is developed somehow independently.
I am not 100% sure if this is something that you have been looking for but there is a support for virtual path providers now:
http://codebetter.com/howarddierking/2012/10/20/new-web-optimization-pre-release-package-on-nuget/
Can you explain your scenario a bit more? My guess is the answer is no, if what yare looking for is whether bundling will effectively drill down and fetch the contents of urls and then minify/bundle them.
We are planning on adding virtual path provider support in the next release which might enable this scenario as you would then be able to write a VPP that could serve up the JavaScriptResult to the bundling system.
Does that make sense?

How to store Application Messages for a .NET Website

I am looking for a method of storing Application Messages, such as
"You have logged in successfully"
"An error has occurred, please call the helpdesk on x100"
"You do not have the authority to reset all system passwords" etc
So that "when" the users decide they don't like the wording of messages I don't have to change the source code, recompile then redeploy - instead I just change the message store.
I really like the way that I can easily access strings in the web.config using keys and values.
ConfigurationManager.AppSettings("LOGINSUCCESS");
However as I could have a large number of application messages I didn't want to use the web.config directly. I was going to add a 2nd web config file and use that but of course you can only have one per virtual directory.
Does anyone have any suggestions on how to do this without writing much custom code?
In your Web.config, under appSettings, change it to:
<appSettings file="StringKeys.config">
Then, create your StringKeys.config file and have all your keys in it.
You can still use the AppSettings area in the main web.config for any real application related keys.
Put the strings in an xml file and use a filewatcher to check for updates to the file
Put the strings in a database, cache them and set a reasonable expiration policy
You can use ResourceManager class. See "ResourceManager and ASP.NET" article at http://msdn.microsoft.com/en-us/library/aa309419(VS.71).aspx