Is it possible to change web.config values based on the hosting environment, such as iisExpress - iis

I am developing a .net core 3.0 web app with a very simple web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<serverRuntime uploadReadAheadSize="10485760" />
</system.webServer>
</configuration>
However, I want to change the web.config file so that this configuration is active with iis, but not with iisExpress, where the permissions to change uploadReadAheadSize are locked.
Surely there must be a simple way to do this, but all my googling hasn't given me a straightforward answer

Due to the design, there seems to be no way to tell from within web.config whether the hosting server is IIS or IIS Express.
But because IIS and IIS Express use different configuration file path, you can move such configuration elements from your web.config file to the desired applicationHost.config file.

Related

How do I deploy Blazor WebAssembly Core Hosted Self-Contained App to IIS [duplicate]

This question already has an answer here:
asp.net core web api published in IIS after moved to different IIS server pc gives error 500.19 (0x8007000d)
(1 answer)
Closed 2 years ago.
I have developed a Blazor WebAssembly App that will be used on a Server running Windows 2012 on our Intranet. This is targeting .Net 5.0 Core Hosted and Self-Contained. I need to deploy to IIS 8.5 and have some questions.
When I add the website in IIS, do I point to the root deploy directory with the executable and web.config?
Is there anything else I need to do so that IIS will find the index file in the wwwroot sub-directory?
Is is appropriate to put the deploy directory for this app directly under inetpub?
The publish task created a rather large BlaorDebugProxy directory. This is for release so I don't understand why this was created. Is there a way to prevent this from happening?
I want to access the app using ServerName\AppName. If I create the site with 'AppName' for the host name, will that work or is there something else I need to do?
When I try to browse to the site from IIS, I get a 500.19 'The requested page cannot be accessed because the related configuration data for the page is invalid.' I have not made changes to the file as it was created by the publish process. It is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\AppName.Server.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 60862cf1-bea8-48f4-8ae9-270f2f537927-->
Any ideas why this is not working?
PLEASE NOTE that this is using the SELF-CONTAINED model.
Also, I have made sure that the directory has granted full permissions to the App Pool Identity for this App.
The answer below and the supposed duplicate all refer to installing the framework. However, I thought that the whole point of the self-contained model is that it does not rely on an installed framework.
I have searched extensively and see many references that touch on these issues but nothing that says specifically how to get IIS (especially an older version) to host the self-contained model. The Microsoft pages talk about advantages and disadvantages and how to create the files but no details about how to host them or the other questions I listed above.
Has anyone done this successfully who can provide some guidance?
Thanks !
Firstly, please ensure that the Asp.net Core IIS Hosting Bundle installer has been installed on the server.
https://dotnet.microsoft.com/download/dotnet/5.0
Besides, the identity under where your web application runs in IIS should have full access to the root folder of your website. Try to grant the IUSR account full control to that physical path.
Last, please refer to the below link to hosting Core-based web application in IIS.
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1
Feel free to let me know if the problem still exists.

Custom Functions not working for IIS hosted Office Excel add-in

We deployed Batching Custom functions project into IIS as hosted application. Task-pane is working fine with API. But when trying to invoke as custom functions facing issue
Error in loading custom functions
at the bottom of add-in. We developed using webpack.config.js but little confused when deploying on IIS for exact server running. So do we need to use express js to run separate port or directly shall we run only enough webpack.config.js file? Kindly confirm on this deployment process.
Also Taskpane related API's are able to fetch successfully but only facing issue with custom functions related API.
You may can check if custom function related files can be seen in your website hosted by IIS. You can have the url information in manifest file.
Would you please check whether you could access the JSON file by browsing to http:///custom-function.json? Would you please also check whether the mime type is correct? If the mime type is not correct, you may need to update the web.config, such as
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
By the way, to make it work for Excel online, you also need to enable CORS access to the custom-function.json

Can't get SVG served from Azure

I'm building a static HTML5 web site on VS2014 and deploying via Dropbox to be hosted on Azure. All works using F5 on VS2014. But my SVG images do not get served from Azure. I get HTTP/1.1 404 Not Found errors. I have tried this solution:
Use SVG in Windows Azure Websites and the code snippet suggested by Mads Kristensen at http://madskristensen.net/post/prepare-webconfig-for-html5-and-css3. My web.Debug.config & web.Release.config files are both as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<staticContent>
<remove fileExtension=".svg"/>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
</system.webServer>
</configuration>
Here's the question. What should I do to get my svg files to download?
EDIT: I found the problem. As a relative new user of VS2014 and Azure, I overlooked the higher level Web.config file and only worked with the lower two files mentioned above. Putting the additional staticContent lines into the Web.config file fixed everything.
I found the problem. As a relative new user of VS2014 and Azure, I overlooked the higher level Web.config file and only worked with the lower two files mentioned above. Putting the additional staticContent lines into the Web.config file fixed everything.

Google Earth (.kmz) mime type IIS issue

I am experiencing a peculiar issue with IIS and KMZ files. I have added the MIME type to IIS and it works just fine -- however, seemingly randomly the MIME type is removed. This has happened a few times now, and each time all I have to do to fix the issue is just add the MIME type again.
The issue is identified when broken links are reported, and as soon as I add the MIME type back in all is well.
Any thoughts on what is causing it, or methods for finding out what's causing it?
Thanks!
My guess is that someone is overwriting or modifying your web.config file. You can modify the web.config using either the IIS server tools or by publishing the project containing the web.config file. If you are modifying your IIS settings using IIS Manager, then every time someone re-publishes the web application it changes those settings. Make sure the correct settings are saved in your web.config in your root VisualStudio project. So that whenever that project is published it's setting the correct IIS settings.
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".kml" />
<mimeMap fileExtension=".kml" mimeType="application/vnd.google-earth.kml+xml" />
<remove fileExtension=".kmz" />
<mimeMap fileExtension=".kmz" mimeType="application/vnd.google-earth.kmz" />
</staticContent>
</system.webServer>
</configuration>

HTTPModule and Sharepoint Site

I am running into an issue with using a HTTPModule with a sharepoint deployed site. Here is what I have:
my asp.net pages inside the /layouts/[ProjectName]/ folder. The aspx file uses a sharepoint masterpage
i have a HTTPModule and implments IHTTPModule
the web.config contains
{httpModules}
{add name="HTTPModule" type="HTTPModule, [fullname assembly]WebForms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=370ae5aba0a4672a"/}
{/httpModules}
The web.config is placed layouts/[projectname] folder.
But for whatever reason, it looks like the HTTPModule doesn't get picked up.
I've verified that:
the assembly exists in GAC and the publickeytoken and all the stuff is correct.
the GAC'ed assembly does contain the code for HTTPModule
web.config is being picked from the layouts folder.
httpmodule isn't being picked (i am throwing exception in the init, session start to have it break on me... but it doesn't throw those exceptions)
Is there some reason the HTTPModule isn't being picked up.
p.s: I am basically trying to do this http://vspug.com/dwise/2007/01/08/one-master-to-rule-them-all-two-actually/
The web.config file that you need to update is the one located in the web application directory (IIS directory).
If you’re running IIS 7.x in integrated mode, you use the section shown here instead:
<configuration>
<system.web>
...
</system.web>
<system.webServer>
<modules>
...
</modules>
</system.webServer>
</configuration>

Resources