I have following problem:
In my application, I have config file, which I use to alter settings needed for standalone installations of the application.
In the settings, there is variable "OffLineServerAddress", which is set to "169.254.2.2"
The application only uses this variable, it is NOT changed anywhere in the program.
The user says (and log file confirms it), that the address, which he uses, is different. It corresponds with address of his virtual box.
Default addres in app.config file is "127.0.0.1"
Apparently, the program uses ip addres of virtual box instead of address from the config file.
I can not think about any way, that this is possible and unfortunatelly I can not post here reproducible code.
I can confirm, that config file of the user has the correct ip address and that the value of the variable is not changed programmatically by the program.
Does anyone know about some way, in which this behavior could happen?
thanks
Got the solution - problem was in saving of default settings.
Related
Creating a Nancy self-hosted console application requires the local address including the PORT as parameter:
using (var host = new NancyHost(new Uri("http://localhost:1234")))
{
host.Start();
Console.ReadLine();
}
While customizing the PORT is a valid use case, is it possible to use another HOST than ("http://localhost"). If yes, which ones and for which reason?
Backgroud:
I am creating a custom settings file for the server and I wonder if it is enough to provide a setting 'Port' or is it better to provide a setting 'Host' (or 'URL') that includes the HOST as well as the PORT?
Edit
To avoid hardcoding, the HOST part may be configurable via application settings (App.config) which is different to the custom settings file that is used by the server's administrator. However, I want to keep the custom settings file as simple as possible. Therefere, the question: Is there is any thinkable reason that the part 'http://localhost' should be modified?
The NancyHost constructor needs a valid Uri object, and to create that you can't get around specifying a HOST. Depending on your application make the HOST editable either inside your program, some form of communication or via a settings file. Do not hardcode the HOST as localhost, even if you think it's gonna stay that way, it's good practice to keep things modifiable. If you want your settings file to be as simple as possible, split it into 2 files:
basicSettings
advancedSettings
where advancedSettings only contains things you rarely, if ever, change und basicSettings contain the things you expect to be changed more frequently.
There might be a case at some point in time where you want to connect to another host because NancyHost has moved, either to the cloud or another system in the same network(the latter is more probable). Just in case this happens you should make it modifiable.
I am following the link to save text to image from the following link:
How to generate an image from text on fly at runtime . Taken the code from the accepted answer .
It is working fine in local machine.
The same program is promoted to a build server in a remote machine. And the url I am accessing from my local machine to save the text to image.
The output says "Image is saved", but actually the image is not saved in the path saved in web.config of remote server.
I am not even getting any error message to know whats the problem as there is no exception.
I am running out of ideas as in what could be the issue and why the image is not getting saved. Any suggestions?
Here are some things you can do:
Make sure the folder where you are writing to foresees modify rights to the IIS Apppool identity of the application. You'll need to add it by searching for it in full instead of just the identity, so
IIS APPPOOL\YourAppsIdentity
(note the space between IIS and APPPOOL) and be sure to set the search location to the server machine, not to the domain, which is what it would default to if the machine is joined into one (otherwise the name won't resolve).
In your application's Web.config file you could also set <customErrors mode="Off"> (in the <system.web> section) during development so you get some more verbose error descriptions in the browser window if or when exceptions do bubble up. They can help you on your way to figure out what's going wrong. Don't forget to remove the entry from the Web.config file again once the application goes into production or set the value to "On" if you do, in fact, use custom errors.
You can make this code a little more robust by doing some access control checks on the directory before attempting a write operation. this can help you on your way.
Hope this helps.
I've created a very simple Windows Form application that uses .NET 2.0 and runs from a single executable.
These single executables will be deployed to multiple users to prompt and collect information.
The catch is that I want to have the information emailed to a specific email address that can vary based on the user the executable is sent to. But, I do not want to rebuild the executable when the email changes.
I can pass command arguments to the executable via command line of course or a shortcut, but I simply want the user to enter information into the form and click submit and have it sent to a predefined email address that can vary based on the user the executable is sent to.
I can bundle the executable with a batch file that runs the executable with the command argument or a config file. But, I want to keep the deployment simple, one file if possible.
Is it possible to do this with an MSI? Am I totally missing something obvious here?
I want the person who is sending the executable out to the user to be able to easily change the email address that the WinForm will send the data to.
if your users are going to be changing the email address you might want to think about a simpler delivery mechanism than a config file, which is fragile in the sense that if a user deletes a > accidentally your app will throw System.Configuration.ConfigurationErrorsException.
One simpler solution than the app config file would be a text file with just the target email address in it, included in the same directory as the app. Your users would have an easier time editing it - or just dropping a new file in. Of course this relies on them having rights to that directory.
Another option is to treat it like a normal setting. Prompt the end user for the actual email on first run, and store it using a user specific setting, i.e. Properties.Settings.Default.SettingName. Then, give your users a UI function to change it on demand.
You could use an app.config file.
Right click the project and select Add->New Item->Application Configuration File
Have something like:
<configuration>
<appSettings>
<add key="UserEmail" value="test#test.com" />
</appSettings>
</coniguration>
And in your code retrieve the config value like:
string email = ConfigurationManager.AppSettings["UserEmail"];
Then you just need to change the value in the config file before sending it to the user, and they can also update it on their own.
One slightly different solution would be to have every instance send email to the same email address, with the 'from' being an address based on the user's Windows logged in account and domain.
Then, create a receiving email account that those emails arrive at with a filter to redirect the mail to the appropriate destination. You didn't say what email system you were using, but Exchange allows this quite simply, for example (as do other systems like GMail).
A more labor-intensive variant on this centralized design would be to create a small web service that your exe queries, with the web service telling the exe where it should send mail to. Again, you'd need a mapping table between Windows user and 'To' addresses.
I'm not sure if I understood your question, but here's my try:
You should check out the properties in visual studio:
Project -> yourProjectName Properties... -> Settings
There you can create variables, which can be either application or user scoped. By using user scoped variable, lets say userEmail, the program lets you save this information according to the logged in user. This way you can save like 20 different emails in this very same executable, depending on the logged in user.
Save the emails according to user:
Properties.Settings.Default.userEmail = "myemail#host.com";
Properties.Settings.Default.Save();
And read them the same way:
string email = Properties.Settings.Default.userEmail;
I have a program which I want to store information in a string. I have been using the Properties.Setting.Default.STRINGname to store the information, which works fine on my PC, and I can see the saved strings (when I go to the settings in the application). But when I take the application to a new PC it losses the strings. Is there a way to be able to edit this information and save it in the app? So basically I need to be able to convert the user setting to application setting, but after the runtime.
var settings = Properties.Settings.Default;
settings.H1 = textbox1.text;
settings.H2 = textbox2.text;
settings.Save();
MSDN explicit says something about this:
Settings that are application-scoped are read-only, and can only be changed at design time or by altering the .config file in between application sessions. Settings that are user-scoped, however, can be written at run time just as you would change any property value. The new value persists for the duration of the application session. You can persist the changes to the settings between application sessions by calling the Save method.
For this, Application setting will never work for you. However, if you are using a User scoped settings it does work, but soon you change the application from one computer to another (as you say you want to) you will loose the settings as that's another machine (another user-scope)...
There are way to continue to have the same settings, you can do, at least 2 things:
use a .config file to save the settings (it's an XML file)
use a service to host the settings and you can read if user has internet access
What you can't do is
using only one executable file, save the settings from computer to computer.
User settings are compiled differently than Application settings, and thus cannot be converted after compilation. Why not compile with Application Settings?
The code you are using should save the user settings. Rememeber that user settings will be saved in the user's data folder. Not in the configuration file where the app was installed (say program files). This is the usual path:
<Profile Directory>\<Company Name>\<App Name>_<Evidence Type>_<Evidence Hash>\<Version>\user.config
See this links form more information
i have an application wherein i am using a web-service. Now the ip address of the machine where this web-service was residing has changed.
i try to update the web reference in my application and it is still trying to access the web-service from the old location. How do i change this to the new location.
I have already updated the new location in my web.config file.
Please help!!
Thank you.
Right click the service, Choose configure and change the address.
If you're getting an unspecified error you could always remove the existing reference (which will break the build, so don't check anything in), then add the new one. Build and test to make sure it works and then check it in to source control.