ChartImageHandler and web farm environment getting 404 error - c#

I am using asp.net ChartImageHandler to generate charts in my .aspx pages, Everything was working great until we tested application on a web farm environment.
The problem is that for some requests, Chart returns 404 error and cannot find the image, This is the config that we use:
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;deleteAfterServicing=false;" />
</appSettings>
I guess that it is because the chart is stored in one server and not stored in the other server.
I have this section in my web.config file:
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3986ad364e35" />
ChartImageHandler is present in the handler mapping of site created in IIS.
As said in documentation page in here, What I understand is that for web farm environment, we should set the storage to file and the other two options are not applicable to web farm environment.
the dir path should be a network path and I tried this network path but it didn't work either ! here what the config look like with the network directory:
And also the network address \\serverIp\TempImageFiles is accessible from windows explorer.
Any suggestion for making this work is much appreciated !
Edit: We changed the affinity of load balancer and everything worked fine.

Related

ASP.NET Core + Framework in IIS getting HTTP 404

Ok - this is my first deployment of an ASP.NET Core app. One wrinkle to keep in mind is that I am using ASP.NET Core 2.2 and targeting Framework version 4.6.2 (not .Net Core). It all runs fine on my local machine with VS2017 and IISExpress.
I went through the procedure outlined by MS here: Host ASP.NET Core on Windows with IIS The documentation is long and complicated, but I think I covered everything. It makes one thing clear: The in-process hosting model isn't supported for ASP.NET Core apps that target the .NET Framework. So, I know I need to use Out-of-Proc.
Some other points:
I published the app to a local folder and copied it to the server without any changes.
I created the new app in the Default Web Site and gave it its own app pool - set as "No Managed Code"
Out-of-proc is the default, so I have not done any special config for this.
I have confirmed that AspNetCoreModuleV2 appears in the list of Modules.
The Result
Every page I hit I get HTTP404. I am running IE locally on the server and using a URL like: http://localhost/MyApp/Home/MyView
The application pool shows having 1 application running.
The App Event Log shows a message like: Application '/LM/W3SVC/2/ROOT/MyApp' started process '8864' successfully and process '8864' is listening on port '37706'. It shows no errors.
I have tried adding a default.htm file to the root of the app and loading the static page directly (using http://localhost/MyApp/default.htm). This gives 404. If I remove the web.config, this page will load.
I really didn't expect deploying the app to be this complicated.
Can anyone provide any guidance on how to troubleshoot or fix this problem?
Update 1: Web.config is below. I have tried with and without hostModel=... aspNetCore logs show successful startup. Nothing is added to the log with each page access attempt (seems weird)
<?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="AspNetCoreModuleV2" resourceType="Unspecified" />
<remove name="BlockViewHandler" />
<add name="JavaScript" path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="CSS" path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
<aspNetCore processPath=".\My.App.Name.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
<environmentVariables />
<handlerSettings>
<handlerSetting name="debugLevel" value="file" />
<handlerSetting name="debugFile" value="d:\Log\MyApp.log" />
</handlerSettings>
</aspNetCore>
</system.webServer>
</configuration>
<!--ProjectGuid: ee76911e-decb-48b7-bd74-36ebfbdb22b6-->
Solved! I was making use of the ASPNETCORE_ENVIRONMENT environment variable, but was unaware that the publish process does not put this in web.config. I added this to Web.config:
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
and the pages now load.
The most useful diagnostics I found were at this link Troubleshoot ASP.NET Core on IIS There they recommended that I run My.App.Name.exe from the command prompt. This creates a web process and assigns it to a port and gives you all the console output. This allowed me to figure out it was actually half working and that led me to the fact that I was missing the Env Variable.
Thanks again for the suggestions...

how to redirect from folder in a web server

i have two different applications, one is a website project running on the the server root, the second is a web application project in a folder, both projects have their configuration files, and i am putting the link in the configuration file of the website project
i am trying to redirect users from the website project to the web application project, whenever i use this:
<add key="CoronaPortalAddress" value="http://localhost/coronaportal/Security/ApplicantSignIn1.aspx?applicationType=" />
<add key="CoronaPortalSignInPage" value="http://localhost/coronaportal/Security/SignIn.aspx" />
<add key="CoronaPortalTimeTablePage" value="http://localhost/coronaportal/Conona Schools_ Trust Council_ApplicantTestScores/TimeTable1.aspx" />
<add key="CoronaPortalResultsPage" value="http://localhost/coronaportal/ParentReportLogin.aspx" />
users will be redirected, though on the url it will showing localhost, so i change it to:
<add key="CoronaPortalAddress" value="http://www.shodsystems.com/coronaportal/Security/ApplicantSignIn1.aspx?applicationType=" />
<add key="CoronaPortalSignInPage" value="http://www.shodsystems.com/coronaportal/Security/SignIn.aspx" />
<add key="CoronaPortalTimeTablePage" value="http://www.shodsystems.com/coronaportal/Conona Schools_ Trust Council_ApplicantTestScores/TimeTable1.aspx" />
<add key="CoronaPortalResultsPage" value="http://www.shodsystems.comcoronaportal/ParentReportLogin.aspx" />
now it throwing error:
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS
i tried to google this, but couldnt fix it, any assistance would be appreciated.

asmx on an existing site gives me namespace not found

Been looking around but cannot find an answer. I wrote an asmx on VS2012 locally works good. Now deploying to the remote target site it is becoming an issue. On that site there are other asmx services and in their global web.config they have this section
...
<system.webServer>
...
<handlers>
...
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=123456789" />
...
</handlers>
...
</system.webServer>
I placed my asmx on a subfolder defining an Application on IIS8 and I'm trying to overwrite that global setting with my local web.config, tried different permutations on the local web.config with location to avoid inheritance but so far it always gives me the lovely
Server error in '/my_svc' Application
CS0246: The type or namespace name 'ForeignNS' could not be found
Is it possible to override it by only changing my local web.config? If so how? If at all possible? Target site admin will not allow to change global web.config unless it is absolutely necessary.

Default Role Provider could not be found on IIS 7 running .NET 4

Good morning all,
I am attempting to implement my custom membership and role providers in my web application that I have implemented under the Default Web Site in my instance of IIS 7. My web application is running under a .NET 4 application pool.
However, after setting up the corresponding web.config, I get the following error:
Parser Error Message: Default Role Provider could not be found.
I have included the following block of code in the system.web section of the corresponding web application's web.config:
<membership defaultProvider="CustomMembershipProvider" userIsOnlineTimeWindow="20">
<providers>
<clear/>
<add name="CustomMembershipProvider" type="CustomProviders.CustomMembershipProvider,
CustomProviders, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=3563615169617648" applicationName="/"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="CustomRoleProvider">
<providers>
<clear/>
<add name="CustomRoleProvider" type="CustomProviders.CustomRoleProvider,
CustomProviders, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=3563615169617648" applicationName="/"/>
</providers>
</roleManager>
Now I have seen all sorts of explanations as to how solve the error that I mentioned earlier. Most of them seem to suggest that I add tags to my provider blocks.
Some seem to suggest that I remove the role manager from the machine.config. And some still seem to suggest not removing or adding anything. This last approach does not seem to account that my web application is being run from IIS and not a local machine.
In the end, I have have tried these approaches to little avail. Can someone please explain to me how I can get passed this error? Thanks in advance!
I got this error when using the default MVC 4 web application.
I had to add the following to web.config and the error went away.
Under <system.webServer>
add
<modules>
<remove name="RoleManager"/>
</modules>
Two things:
enabled="false" should probably be enabled="true"
And I'm not convinced the applicationName="/" is helpful, but it may not be hurting, either.
I got this error message when adding an application in IIS 8 to our existing web site (Right-click on the website in IIS, select "Add Application"). The application's web.config only had the default tag, which was removing the default provider that the web site's web.config defined.
I removed the RoleManager tags completely from the application's web.config, and then the website and application started working properly.

Can't access /elmah on production server with Elmah MVC?

I installed the elmah.mvc nuget package and kept the default configuration of that sans setting up sending an email and plugging it into a SQL database.
On my local machine when I use the Visual Studio host, I can open my app and access /elmah fine to see a report of the errors. However, when I try and access /elmah on production, I get two errors, first I get a 403 access is denied server error. Then in my email (from elmah) I get:
System.Web.HttpException: Server cannot set status after HTTP headers have been sent.
Anyone know what is going on here and how to fix? Thanks.
I tried the following so far as suggested by the answers below:
In <system.webServer>
<handlers>
<add name="elmah" verb="GET" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
</handlers>
And in <system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
I tried setting the path to both elmah.axd and simply ~/elmah. All still give the same error, and still works locally, but not in production.
Edit: It actually also works when I remote into the server and access it via browser on there (not using localhost, but the actual site address). So what permission am I not having? Seems like it's at the server level.
You need to enable Elmah for remote access by adding the following configuration setting to the <elmah> section in your web.config file. The default setting for this value is false, which only allows localhost, hence why it is working on your local machine from within Visual Studio.
<elmah>
<security allowRemoteAccess="true"/>
</elmah>
I always seem to forget this myself and spend a few minutes scratching my head ;)
Make sure you HttpHandler is defined in the webServer section in your web.config file.
<system.webServer>
<httpHandlers>
<add name="elmah" verb="GET" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
</httpHandlers>
</system.webServer>

Categories