I am using IIS 8 on Windows 8.1. I have an XML file an I need to have it accessed through (servername)/(path)
(path) is predefined by someone else and does not contain an extension. I tried the simple solution of removing the .xml file the file name, but IIS returns HTTP Error 404.3 - Not Found
In the "Physical Path" returned with the error is the correct file path, which when I copy-paste to Run opens the correct file.
Please let me know if this is possible.
Assuming (path) is a physical directory on your machine, create a new web.config file in that directory with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="text/xml" />
</staticContent>
</system.webServer>
</configuration>
You are telling IIS that for this directory only, any file without an otherwise defined extension (in MIME types) should be considered an xml file. Other file types in the same path should still work.
If you have the Windows feature IIS Management Scripts and Tools installed, you can use PowerShell to create such a web.config file:
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site/.well-known' -filter "system.webServer/staticContent" -name "." -value #{fileExtension='.';mimeType='text/xml'}
in this example Default Web Site is the name of the web site and .well-known is a directory under that site.
It can be done in IIS 6 as well / without using web.config, but instead using the management GUI to add a MIME type for extension . here:
For instance, to serve a .well-known/acme-challenge token, create a virtual directory called .well-known, and have it take its contents from a physical directory (that cannot have names with leading dots in windows). Then add a text/plain MIME type for the extension . in this directory, and you can manually acquire new letsencrypt certificates for a domain that is currently served by an old IIS.
Changing the configurations by hand can be error-prone. So Internet Information Server (IIS) console GUI provides an easier and error-free way to update the MIME-types. Please follow the steps below:
Open IIS
Expand your website's node in the left navigation pane.
Select your application or virtual directory.
Double-click MIME Types feature under IIS section in the right pane:
Click Add.. link in Actions pane. Set-up the mime type to support all files without extension. Then click OK :
Behind the scene, these steps make changes to web.config file of your application or virtual directory (under your website) as suggested in PeterHahndorf's post.
Note: The screenshots shown in the steps above have been taken from Windows 10 machine having IIS v10.
for me, I want only to serve one file
so what I did is just add a simple rewrite as the other methods posted here didn't work for some reasons
<system.webServer>
<rewrite>
<rules>
<rule name="apple-app-site-association" patternSyntax="ExactMatch">
<match url="apple-app-site-association" />
<action type="Rewrite" url="/apple-app-site-association.txt" />
</rule>
</rules>
</rewrite>
</system.webServer>
Related
I'm working aroung IIS config files.
I want add some IIS IP address restrictions at server level, that spread over all the IIS appPolls
If I work with IIS Manager all work fine, I'm able to add any config settings. But if I want modify/add them directly on .config file it is no possible.
I can see that the settings made by IIS Manager are written on a temporary .tmp file under C:\inetpub\temp\appPools and then overwritten on DefaultAppPool.config under C:\inetpub\temp\appPools\DefaultAppPool
If I try to manual modify DefaultAppPool.config it don't take effect on IIS Manager and if I make any changes on IIS Manager it is overwritten. If I try to manual modify the tmp config under C:\inetpub\temp\appPools I'm informed that the file is in use.
I've also try to work with applicationHost.config under C:\Windows\System32\inetsrv\config, but it does not seem to match the configuration displayed on IIS Manager.
So how can I edit the IIS configuration file manually at the server level?
I've to add a lot of IP restrictions and the only way is to add them directly on .config file.
Very thanks for any help
That is the temporary file. if you want to change the iis configuration at the server level then you could modify the iis applicationhost.config file.
ApplicationHost.config is the root file of the configuration system when you are using IIS 7 and above. It includes definitions of all sites, applications, virtual directories and application pools, as well as global defaults for the web server settings (similar to machine.config and the root web.config for .NET Framework settings).
Open notepad as administrator and open applicationhost.config
add below code in the config file:
<ipSecurity allowUnlisted="true">
<add ipAddress="192.168.2.52" allowed="true" />
</ipSecurity>
https://learn.microsoft.com/en-us/iis/get-started/planning-your-iis-architecture/introduction-to-applicationhostconfig
I'm posting this and answering it, because this left me stumped for a very long time. I have the following line in my web.config:
<aspNetCore processPath="dotnet" arguments=".\XXX.Server.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
So apparently, this should be logging to logs\stdout, but when I look, there's nothing there. I went on a wild goose chase, searching the whole disk for anything named 'log' (that returned too much) or 'stdout' (that returned nothing), and still couldn't figure it out.
You could probably check the Event Viewer on your machine -> Application to see if there are any errors logged, which could explain why your log files aren't being generated.
However, the most probable reason is that IIS doesn't have a permission to write to that log folder.
Right click on the folder -> Security
Ensure that IIS_IUSRS user has the following permissions: read and execute, list, write (potentially write is missing by default)
You must make sure the log folder exists! IIS won't make it for you. Such a simple solution to this infuriating problem.
Update - Nov 2022
The Microsoft documentation on Setting up logging for Asp.Net Core on IIS now specifically lists creating the 'Logs' folder as one of the steps. This implies that IIS will not create the folder if it doesn't exist.
This issue was raised in the Asp Net Core Module's repo on GitHub: Issue #30 - Logs are not created if the log folder does not exist. Their suggested workaround is to include a dummy '.log' file in the log directory, so that the log folder is created when you publish the site.
I created the logs folder but still, nothing was logged. I found out that you can use an existing folder under home/logfiles and make it work without creating a folder. This solution worked for me as is:
1) Open the web.config file that is created in the root folder of the published application.
2) Set stdoutlogEnabled to true and stdoutLogFile to \?\%home%\LogFiles\stdout like this:
<aspNetCore processPath="dotnet" arguments=".\SellCarsHereV2.dll" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
Then you can either go to that path and download the files or use the Azure Portal (if it's hosted in Azure). If you are using the Azure Portal:
1) Go to the app service.
2) Go to Advanced Tools which takes you to https://{your app service}.scm.azurewebsites.net/
3) Click on Debug Console menu --> CMD
4) Click on LogFiles
5) You'll see a file called stdout_*.log and you can click on the pencil to view it. You can also download the file if you want.
According to the provided stdoutLogFile=".\logs\stdout" in your web.config file, the logs directory should be created next to the web.config, inside the publish directory.
To create the logs subdirectory you can use the approach described in the ASP.NET Core directory structure.
Just paste this at the end of your published project's *.csproj file
<Project>
...
<Target Name="CreateLogsFolder" AfterTargets="Publish">
<MakeDir Directories="$(PublishDir)logs"
Condition="!Exists('$(PublishDir)logs')" />
</Target>
</Project>
During the publish process after this change the logs directory should be created if it does not exist in the output directory.
If you run for example:
dotnet publish --output <path_to_your_publish_folder> you should find the logs directory inside the <path_to_your_publish_folder>
I did the following steps in order to get logs:
Create a folder logs and give write access to IIS_IUSRS as described above
Set absolute path in web.config: stdoutLogFile="C:\xxx\xxx\logs"
Recycle the the application pool
Stop, Start the Website
Edit
Step 2 works with relative path too stdoutLogFile=".\logs\stdout"
Check the event viewer. If you're like me you will see an entry in the Application\Event log "Could not create stdoutLogFile c:....logs\stdout_....". You have to create the logs folder there yourself. Once I created the "logs" folder stdout_.... files began to dump into it. Of course also be sure stdoutLogEnabled="true". The location of the expected folder location will be shown in the event viewer log. This is important because it may not be where you think it should be located.
I noticed that the logs are not created immediately when you hit the website. I allowed write access for IIS_IUSRS, created 'logs' folder, restarted app_pool and after few minutes logs were there.
I cannot find any information on how to perform URL Rewriting on IIS (windows 10). I develop websites on windows but have a linux server which uses a htaccess file for URL Rewriting.
The issue here is, I find it far too time consuming to manually enter rules into iis with the standard url rewriter. You can't just write them out in a text document like you can on a Linux server with htaccess files!?
Is there some way to use a htaccess file, web.config file, or ionic's isapi (or other) url rewriter on iis (windows 10) to write out all of my websites url rewriting rules? It seems that none of those software packages have support for this operating system/the latest IIS.
Thanks!
I had the same issue, but fortunately there is a handy shortcut in the IIS URL Rewrite 2.1 module that converts .htaccess files directly into the equivalent web.config;
In IIS, double-click on the URL Rewrite module
In the Actions pane, click 'Import Rules'
Paste the contents of your .htaccess file into the 'Rewrite rules' text box
Viola, your .htaccess rules are converted into IIS web.config rules
There is an article here: https://blogs.msdn.microsoft.com/azureossds/2015/04/23/converting-apache-htaccess-rules-to-iis-web-config-using-iis-manager-for-azure-websites/ that provides an illustrated step-by-step guide to the process. The article is specifically aimed at Azure, but I use IIS on Windows 10 for localhost dev and it works just fine.
All rules for the IIS URL Rewrite module are stored in text files, either your local web.config or the global ApplicationHost.config file. You can also use a custom config file like rewrite.config and include it in your web.config like:
<system.webServer>
<rewrite>
<rules configSource="rewrite.config" />
</rewrite>
</system.webServer>
IIS url rewriting is the same for all IIS Version since 7.0 on Server 2008 and nothing had changed in Windows 10, there are lots of resources about it out there.
I have an Azure shared web site. I publish my web site using Visual Studio 2013 and the operation succeeds, yet certain files are reported by the browser as missing while others are fine. The files that end up in the missing category are all binary data files for a game. All the "normal" web files (HTML, JS, CSS, etc.) appear to be fine. Is there some kind of special steps I need to take to publish binary data to an Azure web site?
Note, from within Visual Studio 2013 I tried to publish individually one of the missing files by using the Publish Single File option. The publish operation succeeds, but still, the browser can't find the file when it tries to load it. Note, I don't think it's a file size issue because several of the binary data files are only around 3 MB in size.
To fix this issue, FTP into your website and upload the following Web.config file which will set the correct MIME types. If you already have a Web.config file in place, just add the below to the appropriate section. Replacing .json and application/json with the file you're trying to load.
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
I'm guessing in this instance you haven't configured the mimeTypes for these files, if they are to be served through the server. There's a quick explanation and an appropriate resolution to your problem.
HTH
I'm developing an app. using Common.Logging (http://netcommon.sourceforge.net/index.html).
A simplified logging configuration (which is done in web.config) is as follows:
<configuration>
...
<arg key="configType" value="FILE" />
<arg key="configFile" value="NLog.config" />
...
</configuration>
As you can see here, the configuration points another configuration file (here, NLog.config) of a backend logging framework.
My question is: when deploying in Azure, what path should I specify here (on dev, NLog.config is copied when building the solution, and placed in the bin directory). In other words, what would be the SAFEST way to get the physical place where the app is deployed in Azure?
Thanks in advance!
In code you can find the current path to the application using Server.MapPath("/"). Now, you can simply make sure that the NLog.config file gets deployed to the application folder:
Add NLog.config to your project (in the root of your web application)
Change the Build Action to Content
In order to test this you can right click on your Azure project an choose Package. In the bin\Release|Debug\app.publish folder of your Azure project you'll find a *.cspkg file. Add a .zip extension to this file and open the file with WinRAR/ZIP/7zip/... Then you'll see a file like this one: SomeWebRole_1a91f39a-49b7-4ece-873f-862172a2fa06.cssx. Here again, add the .zip extension to this file and open it.
If you navigate to the sitesroot\0 folder you'll see the files of the web application in IIS, including the NLog.config file. This way, you' can simply reference the NLog.config file in the Common.Logging settings: