Background:
I have an application that for distribution and dependency bundling reasons is installed using Inno Setup, but at its core it's an ASP MVC 5 web app.
I'd like users to be able to install in Program Files as it's a natural place to place programs, and the average user will expect to be able to do this.
The Problem:
Some configuration files are modifiable through the app to admin users. These configuration files take the form of language strings, mail settings, etc.
The problem arises if the application is installed to Program Files. The IIS hidden user account running the application doesn't have write access to this directory, so config files inside the application directory cannot be modified by the application.
The solution I thought of was to place modifiable files inside a folder in C:\ProgramData, which is modifiable by the application. Here is where I hit an error. After changing mail settings to look like this in mt web.config
<smtp configSource="C:\ProgramData\myapp\Config\mailSettings.config" />
I get this error.
Question:
Can I not link configSource to directory outside of the application? If not, is there a way around this?
Cheers.
Related
I have the basic blazor project that im trying to host in a specific way. I have managed to host the app in IIS where all the files were in the same folder. The issue im having is the web config in the root folder and then having the actual app itself in a subfolder.
IIS app file structure
im using blazor server which is sitting the "test" folder.
test folder where the blazor app is, seperate to the web config
Is this even possible to host in this way? or is there routing or config that needs to be done to get it to work?
Thanks,
So far I'm afraid it is unavailable to host application in site level. No matter I set the aspnet core handler in root level or folder level, change location value,change processPath. IIS just ignore the attribute even I have set it in both root level and folder level.
I think even you were able to host blazor in a sub-folder, Duplicate attribute verification is easy to crash the application when you need to publish something in root folder.
So the best way to handle this is convert test folder to an application. Then everything get isolated and start working.
interesting idea
I see no reason, why not to create a sub directory as website in iis. There have to be a extra app pool unmanaged for each.
I have a C# executable reading and updating it's configuration file (app.exe.config) at runtime, specifically, the "appSettings" section. After I make two changes to two key values and save them using the Configuration.Save() method, an "access to the path" error is thrown, but only on some users' machines (so far 2 reports out of 10,000). We have never seen this issue in-house, only in production.
The Configuration.Save() method seems to be the issue based on our program's log file. When a problem with this call happens a "ConfigurationErrorsException" occurs because the configuration file could not be written to -or- the configuration file has changed. The configuration file is in the same directory as the application. This is a Dot Net 4 application running on a Windows 7 PC.
The code is:
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings["Last Updated Package"].Value = packageVersion;
configuration.AppSettings.Settings["Copy Updated Files"].Value = bool.TrueString;
configuration.Save(ConfigurationSaveMode.Minimal);
ConfigurationManager.RefreshSection("appSettings");
The error is:
An error occurred loading a configuration file: Acces to the path 'C:\Program Files (x86)\My Program\bin\guaixcax.tmp' is denied. (C:\Program Files (x86)\My Program\bin\MyProgram.exe.Config)
Is this a permissions issue, or can I add something to either the code or config file to fix this issue?
I have had similar issues with .NET program installations. It has always been a permissions issue. To test if this is your problem, you should try running your application as an unprivileged user - developers tend to have administrator rights...whenever they can manage it.
If it fails, edit the security of the config file (as an administrator) to allow the "Users" group write access to your "bin" folder, and try it again. If it works, you've identified the problem. Then you can figure out what the best solution is. Some options would be:
Set access rights to necessary files/folders from your installer to work for the users that will run the application
Run the application as a user with admin rights (NOT a good idea from a security best-practices point of view)
Instead of modifying the main app settings file, create a separate settings section referencing a file that has the data that can be changed:
<configuration>
<configSections>
...
<section name="MyChangableSettings" type="My.Namespace, ChangableSettingsClass"/>
</configSection>
...
<MyChangableSettings configSource="Path\To\Writable\StorageDir\mySettings.config"/>
</configuration>
One of my folder is reside in local network or local machine for upload and display attachments. I can not manage (upload or display) this in MVC 4.0, ASP.NET. For that I wrote path in appsetting of web.config. Please guide me how to manage it.
Simply having the path recorded and used does not mean that the application has the permissions to access it.
You need to ensure that the account that the web application runs under has the permissions to access this folder (the account details will be in the properties of the web server application pool that is setup for the site).
try to:
create a Site mapped on your attachments folder
In your project, add two AppSettings: AttachmentAbsoluteUrl, AttachmentFullname
When you have to download an attachment, you can use the Url defined in the AttachmentAbsoluteUrl AppSettings Key, when you have to upload/delete/add, use the AttachmentFullname key.
In this way you can manage both development and production environments, using different AppSettings values.
For example, in my local computer, I have the Attachments folder in the same directory of the project, in production server, I have a different folder outside the Site directory.
You have to check if the Identity of the Application Pool used by your Web application have the rights to modify the contents of the Attachments folder.
I hope this can help you
Scenario:
I have two applications, a Windows Forms App and a Windows Service App. The two applications work together, use same libralies (dll) and share the same configuration file (this file is not the app.config but a custom file).
Complications:
I have a website (webforms) where the user will enter information about configuring the software, this information will be saved in the database and from this information will be generated the configuration file. The site should generate build the project with the new configuration file and the page responds to the client's request with a link to download the .msi.
Problem:
How to generate an installer from a command line to be called by the web application after generating the configuration file. I researched and found the Windows Installer XML (Wix), but it seems to be necessary to compile the entire project every time someone downloads. It's possible leave the program compiled and only add the configuration file after?
Apretiate any helps
Light (the linker in the WiX Toolset) has a feature called "cab cache" which will re-use the cabinet files which are embedded in the resultant MSI. You would use the arguments -reusecab and -cc to enable this.
You'll still have to re-build the MSI when the user submits your form, but the build will be faster (cabinet generation is usually the longest part of the build process).
I'm having a "tiny" issue with my App_Code folders.
I'm learning ASP.NET and, therefore, ordered a webserver with the support of ASP.NET 4.0. I'm using Visual Web Developer to program my webpages. When I upload my website to this webserver everything runs fine.
However, if I then add another web project to my server, my App_Code folder gets all messy. The server wants all my class files in the App_Code folder in the root. Is there any way I can create subdirectories in my App_Code folder or something to keep my projects organized or am I missing the point here?
You should take a look at codeSubDirectories in the web.config
Alright I found a solution to my problem. Although most of your answers might work aswell, this proved to be the best in my case. I created a subdomain and threw all files into that folder and it worked fine.
You should try to avoid using the App_Code folder for your own stuff, especially if you're using a web application project.
Whenever you convert a website to a web application project, the process actually renames your existing App_Code directory to Old_App_Code.
See Here, even though this is specific to converting .net 2.0 apps, I believe it still holds true in 4.0 since converting a 4.0 app does the same thing.:
VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes it finds under the /App_Code directory of an application at runtime, you explictly DO NOT want to store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder. If you do this, then the class will get compiled twice -- once as part of the VS 2005 Web Application Project assembly, and then again at runtime by ASP.NET. The result will most likely be a "could not load type" runtime exception -- caused because you have duplicate type names in your application. Instead, you should store your class files in any other directory of your project other than one named "app_code". This will be handled automatically by the "Convert to Web Applicaiton" command. This command will rename the folder Old_App_Code.
If you have access to a hosting control panel it's probably best to configure your hosting environment with a virtual folder for your second website and run it from the sub folder, e.g. www.example.com/project-b. The first site can still be running in the root folder, e.g. www.example.com.
So both sites will essentially be isolated from each other (just like they are now isolated as two separate projects in Visual Web Developer Express). And both sites have their own App_Code folder (and web.config file).
If you don't have access to a configuration panel, most hosting providers are willing to add a virtual folder for you, since it's really not a special requirement.
The virtual folder should show up as a regular folder in your FTP folder, usually inside the www or wwwroot folder. Now you can copy your project files into that folder.
Take care to use root-relative paths for URLs in your second project, so all links will work even when the website is run from the subfolder. Root-relative URLs look like this:
<asp:HyperLink runat="server" NavigateUrl="~/Default.aspx" />
<asp:Image runat="server" NavigateUrl="~/images/logo.png" />
This will automatically go to www.example.com/project-b/Default.aspx and www.example.com/project-b/images/logo.png when the website is deployed in the virtual folder.
If you need to re-use code from one site in the other, it's typically best to move such code into a separate Class Library project type, and then add a reference to that project to each website project (right-click the website project, choose Add reference..., then select the Projects tab and select the Class Library project).