ImageResizer works when testing with Visual Studio - not working on production? - imageresizer

I have ImageResizer installed via NuGet which is working fine when I run the ASP.Net MVC website from Visual Studio. I can get to the /resizer.debug page and it says all is well.
When I come to publish the site from Visual Studio to the main IIS instance on the same machine, ImageResizer does not work and when I browse to /resizer.debug I get a 404 Not Found error.
I have published the web.config and verified all the image resizer components are in there. Eg:
<httpModules><add name="ImageResizingModule" type="ImageResizer.InterceptModule" /></httpModules></system.web>
The ImageResizer dlls are also in the /bin directory.
However, nothing is happening and the debug page will not display.
Is there something that needs to be done to configure ImageResizer on IIS7 when publishing the project?

It appears that you only configured it for IIS Classic, not IIS7 Integrated mode. There must be a <system.webServer> element with the module installed.
From the installation guide:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />
</configSections>
<resizer>
<!-- Unless you (a) use Integrated mode, or (b) map all requests to ASP.NET,
you'll need to add .ashx to your image URLs: image.jpg.ashx?width=200&height=20 -->
<pipeline fakeExtensions=".ashx" defaultCommands="autorotate.default=true"/>
<plugins>
<add name="DiskCache" />
<!-- <add name="PrettyGifs" /> -->
<!-- <add name="SimpleFilters" /> -->
<!-- <add name="S3Reader" /> -->
</plugins>
</resizer>
<system.web>
<httpModules>
<!-- This is for IIS7/8 Classic Mode and Cassini-->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<!-- This is for IIS7/8 Integrated mode -->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>
</modules>
</system.webServer>
</configuration>

Related

Remove WebDAVModule from startup.cs asp.net core

IIS Server gives "Method Not Found Error". After Exploring Google, I got that WebDAVModule should be removed in web config file.
Every time i publish my Project, i have to add this
<modules> <remove name="WebDAVModule" /> </modules>
in Webconfig
Please suggest me how do i add this in Startup.cs or any other solution?
Just add a web.config file to your project, like bellow:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</configuration>
You can do it in several ways
Remove from IIS model
Go to your site in IIS
Click "Modules"
Remove WebDAVModule
Restart site (might not be needed)
Remove from windows features

.net Core API not working on IIS

I'm new to this .NET Core stuff and this is the first time I've tried to deploy one of these.
The project is an API for an Angular front end I'm building and takes HTTP requests and returns JSON. When I run it in Visual Studio on my box it is all fine. I'm running VS2017 and have .NET Core 2.0.0 installed.
I publish to a folder on the web server and it all seems to work fine, but when I try to access the API I get a 404 not found error. The server is running .NET 2.0.6 (I tried to get 2.0.0 but couldn't find it in the Hosting Bundle Installer.
If I delete the web.config the HTML file will then show up, but obviously the API doesn't work. But as the HTML file shows up there is no issue with permissions and access. There's nothing in the Event Viewer. I've also tried turning on the logging in the web.config, but it doesn't log... probably not getting far enough to.
Web config looks like this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\RawMaterialsSystem.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: f01b1621-2ced-4ad2-9ae6-004e03b0e043-->`
STEP 1: Change your web.config file to this
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
STEP 2:
In visual studio, right click the .net core app project and select "Publish"
Then publish it as a folder under bin\Release\netcoreapp2.0\publish
STEP 3:
In IIS --> Sites --> Right click on YourSite --> Under "Manage Website" select "Advanced Settings"
Make sure the "Physical Path" you are pointing to is the "publish" folder as the app directory, and not the "netcoreapp2.0" folder

MSBuild : app.config is getting transformed for given environment but app.exe.config is not getting transformed

I am using MSBuild.exe to build our application. Along with App.Config, I have App.prod.config, app.qa.config, app.dev.config files.
On the command line, I enter following
C:\XXX\MyProject> C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe myBuildFile.build /p:Configuration=DEV
Above command, looks for app.config and app.dev.config files, Transform placeholders in App.dev.config & generate app.config file with entries from app.dev.config file.
After project is compiled, app.exe.config file is created. All this is working fine for me.
But for production, I am getting correctly transformed app.config file but the app.exe.config file is same as the default app.config file (without any transformation)
Following is the app.prod.config file:
<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="EventStore"
connectionString="XXXXXXXXXXX"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
<add name="Profile"
connectionString="XXXXXX"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
<add name="IdentityDB"
connectionString="XXXXXXXXXXXXXXXXXXXXXXXX"
providerName="System.Data.OracleClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</connectionStrings>
<appSettings>
<add key="ApplicationName"
value="PROD"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)"/>
</appSettings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(Debug)" />
</system.web>
</configuration>
By default, web.config is transformed on publish only. If you want to transform app.config or an xml document, then the best option is to install a Visual Studio extension called SlowCheetah

How to publish an MVC 6 website in IIS with multiple apps in the src folder

When I try to publish an asp.net 5 website with multiple web apps in the 'src' folder. It works okay in klr but If I run it under IIS, I get this error:
Failed to resolve the following dependencies for target framework 'Asp.Net,Version=v5.0'
Here is a very basic simple project attached that you might want to run under IIS.
http://www.filedropper.com/iissampleapp
Update: updating my question as requested.
In the attached project, I just right click on "IISSampleApp" and click publish. Visual studio creates files on local file system, which I then try to run under IIS. After publish, both of the web apps reside under src folder as src\IISSampleApp and src\SubApp. The IISSampleApp is the main app that should run as website, and it just references a class DateClass from SubApp.
I have created this sample project to get the answer, my actual project have similar structure and I get the same error.
I have uploaded the Precompiled version of the project here: http://www.filedropper.com/precompilediissample
Below is my generated web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta3" />
<add key="runtime-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta3" />
<add key="kre-clr" value="clr" />
<add key="kre-app-base" value="..\approot\src\IISSampleApp" />
</appSettings>
</configuration>
edit the web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta3" />
<add key="runtime-path" value="YOUR-RUNTIME-BASE-PATH\.k\runtimes" />
<add key="kre-version" value="1.0.0-beta3" />
<add key="kre-clr" value="clr" />
<add key="kre-app-base" value="..\approot\src\YOURPROJECT" />
</appSettings>
</configuration>
and set the security policy for \approotand \wwwroot
update: updating the answer after question's update
That just can't work like this because the kpm bundle command packages website as website and not as class library and you have 2 Startup class which is no good. If you want to share code between 2 website create a class library.

HttpModule not called in .NET 4.5

Just spent a lot of time sifting through contradictory advice on this problem, and thought I'd post my solution.
My environment is .NET 4.5, Visual Studio 2012, working on an MVC 4 application. I created an Http Module like I'd done in the past, and added it to Web.config like so:
<configuration>
<system.web>
<httpModules>
<add name="MyModule" type="Services.MyModule, Services" />
</httpModules>
</system.web>
</configuration>
However, the application never called the module's Init(). Eventually, I found advice that the modules should instead be inside <system.webServer>, and the element named <modules> instead of <httpModules>, like so:
<configuration>
<system.webServer>
<modules>
<add name="MyModule" type="MyModule" type="Services.MyModule, Services" />
</modules>
</system.webServer>
</configuration>
Re-ran the application, and it called Init() as expected. FWIW, the page with the direction is here:
http://msdn.microsoft.com/en-us/library/ms227673.aspx
HTH
<system.web> is for IIS 6 and below (including Cassini), <system.webServer> is for IIS 7 and above. I generally put in both -- just in case -- and then add this node to <system.webServer> so it doesn't barf on the redundancy:
<validation validateIntegratedModeConfiguration="false" />