What is the proper syntax for relative paths in web.config? - iis

I have a site structure like this:
And I'd like to use a relative path to my test_isapi.dll in the web.config for the ISAPI application. I've tried replacing C:\TestSite1\TestSite2\ISAPI\test_isapi.dll with the following relative paths with no luck:
test_isapi.dll
~/test_isapi.dll
~\test_isapi.dll
ISAPI\test_isapi.dll
Do I have the syntax wrong for the relative path, or is this just not possible for handler settings in the config?
Current (working with absolute path) web.config (TestSite1/TestSite2/ISAPI/web.config):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Test ISAPI"
path="*"
verb="*"
modules="IsapiModule"
scriptProcessor="C:\TestSite1\TestSite2\ISAPI\test_isapi.dll"
resourceType="Unspecified"
requireAccess="None"
preCondition="bitness32" />
</handlers>
</system.webServer>
</configuration>

My solution was to programmatically check and add the handler mapping instead of deploying the setting with the web.config. That way I can determine the absolute path at run-time and apply the setting. Not ideal, but it gets the job done.
See this answer: How to add IIS handler mapping programmattically

config you can write ~/filepath

To use a relative path just Add ~/test_isapi.dll for ISAPI Site webconfig.

Related

Web.config setup for IIS development

I am running an IIS instance (Not the default IIS Express) on which I have configured my ASP.NET Core 3.1 MVC project.
I would like to configure my web.config file, so that I have the following behavior:
Each time i update a view (.cshtml file) in my solution, the update is instantly visible after i refresh the page.
Each time i update a controller or a model (.cs file) the update becomes visible after a rebuild of the solution.
What I currently have is the following configuration in my root directory:
<?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="dotnet" arguments=".\bin\Debug\netcoreapp3.1\Live.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
Now with the following configuration I have to rebuild each time I want to see the result of my modifications. There's also another problem, each time I rebuild the app I encounter the following problem:
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4502,5): error MSB3021: Unable to copy file "obj\Debug\netcoreapp3.1\Live.dll" to "bin\Debug\netcoreapp3.1\Live.dll". The process cannot access the file 'bin\Debug\netcoreapp3.1\Live.dll' because it is being used by another process.
I have to manually stop the IIS instance and then rebuild my solution.
I have worked on a project where this was the way things were done, however I never figured out how it was configured. I would appreciate any help if possible, Thanks.

Azure vue issuse with missing server.js/app.js?

I am new to web development and I have tried to upload my vue app to a azure web app service but i am getting some problems
so when I try to try to open the webpage up it says
"You do not have permission to view this directory or page."
I have been trying to follow a few guide about a web.config file, and when i added it, the message disappered, but now it shows nothing. Then i tried to take a look at my output when i try to upload my code, here it says
missing server.js/app.js
my app file is a vue file, but i don´t really know how to fix this, it´s also not located at the root but in a src folder
i added the web config file to the public folder
<configuration>
<system.webServer>
<!-- indicates that the index.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<!-- adds index.js to the default document list to allow
URLs that only specify the application root location,
e.g. http://mysite.antarescloud.com/ -->
<defaultDocument enabled="true">
<files>
<add value="index.js" />
</files>
</defaultDocument>
</system.webServer>
</configuration>

Let's Encrypt confirmation on IIS not working

I'm trying to use the Certify SSL Manager to configure SSL certificates from Let's Encrypt on my IIS server, but it fails during the check.
https://dev.mywebsite.com/.well-known/acme-challenge/configcheck/
This works:
https://dev.mywebsite.com/well-known/acme-challenge/configcheck
https://dev.mywebsite.com/.well-known/acme-challenge/test.txt
So I assumed it's the . before well-known. But the fact that test.txt works confuses me.
I've already configured the directory according to this discussion:
https://github.com/ebekker/ACMESharp/issues/15
I have a bunch of rewrite stuff in my web.config, but even if I remove that section completely, it still fails.
Perhaps check if the acme-challenge web.config contains a conflict within the handler section. Do so by opening IIS manager, find the acme-challenge folder en double click the handler mapping icon. In my case, this resulted in an error.
The problem I ran into with the default web.config in the acme-challenge folder was that the applicationhost.config contained:
<section name="handlers" overrideModeDefault="Deny" />
The handlers section in the acme-challenge web.config therefore was not allowed with the result that the challenge failed. In this case the solutions were:
Change applicationhost.config line to:
<section name="handlers" overrideModeDefault="Allow" />
Or ...
Remove the handlers setting from the web.config in acme-challenge folder.
The applicationhost.config can be found here: c:\windows\system32\inetsrv\config
The configcheck url is a file, not a directory. Make sure that file exists on disk (i.e. C:\inetpub\wwwroot\.well-known\acme-challenge\configcheck) in your webroot. Then try to load your links with this barebones web.config in your website root directory (if using ASP.NET):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="application/unknown" />
</staticContent>
</system.webServer>
</configuration>
If that works, try slowly adding back in your web.config sections including routes/rewrite until you figure out what's causing the problem.
If using ASP.NET Core with a wwwroot folder hosting your static files, you'll have to modify your config in Startup.cs instead:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
string filepath = Path.Combine(Directory.GetCurrentDirectory(), #"wwwroot/.well-known");
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(filepath),
RequestPath = new PathString("/.well-known"),
ServeUnknownFileTypes = true
});
// ... your other startup code here
}
I had to modify the web.config as follow to fix the error:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="*" mimeType="text/plain" />
</staticContent>
<handlers>
<clear />
<add name="StaticFile" path="*" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="true" preCondition="" responseBufferLimit="4194304" />
</handlers>
</system.webServer>
</configuration>

How to install Ghost inside an existing node.js application on Azure?

Can you install Ghost (http://ghost.org) so that it runs inside an existing node.js express application (like this: {my domain}/blog)?
I'm using Azure Websites to host the site.
Please note: I would prefer a generic solution that can run on any platform... however I thought I would mention that it's on Azure in case it provides a simple way to do this.
Yes you can do that.
You will need to:
1. Add a new blog application
Basically go to portal -> CONFIGURE tab -> scroll all the way to the bottom and add something like this
2. Configure Ghost to run on a sub folder
publish Ghost to whichever folder you mapped to your application in the step above.
You can use FTP, webdeploy or SCM (https://<YouSiteName>.scm.azurewebsites.net/DebugConsole
that's what I choose and my folder layout looks like this
igonre the deployments folder, it's not related to this
in your config.js for Ghost, under the Production environment node make sure you have the url as
production: {
url: 'http://<YourSiteName>.azurewebsites.net/blog',
mail: {
......
}
}
3. Fix the main site's web.config
go to your main sites web.config and wrap the whole <system.webServer> element in a <location path="." inheritInChildApplications="false">
basically your web.config should have looked like this
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Some rewrite rules -->
</rules>
</rewrite>
....
</system.webServer>
</configuration>
and now it should look like this
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Some rewrite rules -->
</rules>
</rewrite>
....
</system.webServer>
</location>
</configuration>
notice this is for the main site that is the Express.js in your case not the Ghost site
that should be all you need to do.
Not sure if you can install it as an addition to your existing site, but Ghost exists as a deployable template in the Azure Web Sites gallery, under Blogs:
This is not the complete answer you were looking for, but these instructions on how to manually install Ghost on Azure Websites might help guide you in the right direction:
http://www.hanselman.com/blog/HowToInstallTheNodejsGhostBloggingSoftwareOnAzureWebsites.aspx

HTTPHandler for all files in directory

I have created an HTTPHandler to handle all files within a certain folder ("Files"). When i run it locally from Visual Studio it works fine. However when i deploy it on the server (IIS 7, Classic Mode), the handler is not firing for files of types such as pdf, jpg, gif...etc (although requests for files with extensions .aspx, .axd...etc do work).
How exactly should i configure web.config to handle these files as well. I placed a web.config file inside the Files folder with the following:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.*" type="MyProject.Web.FileSecurityHandler, MyProject.Web"/>
</httpHandlers>
</system.web>
</configuration>
Please help...
add one more element in your HTTPHandler tag for specific file type for example
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.*" type="MyProject.Web.FileSecurityHandler, MyProject.Web"/>
<add path="*.jpg,*.jpeg,*.bmp,*.tif,*.tiff" verb="*" type="NameofYourHandler" />
</httpHandlers>
</system.web>
</configuration>

Resources