I have followed the article http://www.codeproject.com/KB/aspnet/combres2.aspx.
When I run my site I cannot get the combres.axd to work ? I know that the combres is running since an incorrect file in my xml will cause an error. I am running an ASP.NET 4.0 web forms site on vista.
My Combres XML settings are.
resourceSets url="~/combres.axd" defaultDuration="30" defaultVersion="auto" defaultDebugEnabled="auto"
I have checked the web.config for all correct values. The reference has been added from the merge directory and the global ASX file has the following.
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.AddCombresRoute("Combres");
}
I also checked the value is created in the html source.
href="/combres.axd/siteCss/309885723"
src="/combres.axd/siteJs/408582048"
I do not get an error or anything to help me track down the reason it will not work or what I may have missed. Any suggestions would be great.
I had the same problem when trying to get it to work for the first time.
Make sure that the Combres route is added before the call to ignore the route {resource}.axd.
Correct:
RouteTable.Routes.AddCombresRoute("Combres");
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Incorrect:
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.AddCombresRoute("Combres");
First, i'd suggest to hook a log4net to the combres logger in your web.config (don't forget to setup the configsection for log4net)
<log4net>
<logger name="Combres">
<level value="ALL"/>
<appender-ref ref="LogCombres" />
</logger>
<appender name="LogCombres" type="log4net.Appender.RollingFileAppender">
<file value="Combres.log.txt"/>
<appendToFile value="true"/>
<maximumFileSize value="5000KB"/>
<maxSizeRollBackups value="2"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
</log4net>
And in your global.asax launch the configuration
log4net.Config.XmlConfigurator.Configure()
You should have a detailed log of what's happening. If what's wrong doesn't pop out, don't hesitate to come back with some log output
For some reason the only way we could fix showing css in debug=false mode is by adding combres.axd to the anonymous access in web.config
<location path="combres.axd">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
What is your modules setting in web.config? Check for the runAllManagedModulesForAllRequests attribute.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
With a legacy WebForms app, I found I did not have that setting and once I put it in, the combres.axd route worked.
More on my question too
These are the changes i did in the project and it stated to run properly.
In the Global.asax file add these lines
using Combres;
In the application_start method
protected void Application_Start()
{
RouteTable.Routes.AddCombresRoute("Combres");//Add this line
RegisterRoutes(RouteTable.Routes);
}
Comment out the line in Combres.cs file.
This happened to me too but the problem was from Yahoo.Yui.Compressor they changed one property signature in their new version 1.6*.
So to fix it i just down the Yahoo.Yui.Compressor to version 1.5.
And i'm happy now :)
Related
I have made a service that i host on an azure webapp. This will be used to upload files. IIS has a built in security feature that limits the file upload size.
To work around this i have put the following in my web.config
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="80000000" />
</requestFiltering>
</security>
</system.webServer>
...
<system.web>
<httpRuntime maxRequestLength="80000" targetFramework="4.5.2" executionTimeout="9000" />
</system.web>
This is however not working for me. As soon as i upload a large file (50mb for example) it hits me with a 404. When i upload a smaller file (10mb) it works fine. The service is a soap and is called over https. The call does not time out, the exception occurs within 5 seks of the call being made, my guess is it uploads 30mb and then it thinks it is under attack and aborts.
Am i missing something here?
You can go to folder:
%windir%\system32\inetsrv\
run command:
appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:80000000
or if you only want to set it for your app, run this:
appcmd set config "Default Web Site/" -section:requestFiltering -requestLimits.maxAllowedContentLength:80000000
also you need to update overrideModeDefault to 'Allow' in web.config:
<section name="requestFiltering" overrideModeDefault="Allow" />
Then you can have your web.config updated with appcmd.exe
Hope this article and this article will help you.
About how to use appcmd.exe, you can see https://technet.microsoft.com/en-us/library/cc772200%28v=ws.10%29.aspx
After that deploy your project to azure webapp and try again.
I did that configuration, but i fixed my problem putting on my ControllerBase something like:
protected override void OnResultExecuting(ResultExecutingContext filterContext)
{
base.OnResultExecuting(filterContext);
if(filterContext.Result.GetType().Name == "JsonResult")
filterContext.Result.GetType().GetProperty("MaxJsonLength").SetValue(filterContext.Result, int.MaxValue);
}
For classic ASP users also check this settings in addition to the web.config settigns:
IIS > CLick on Website > ASP > Limit Properties > Maximum request entity body limit
In my case, the problem was because the configuration of httpProtocol in the web.config file had the 'allowKeepAlive' in false.
<httpProtocol allowKeepAlive="false">
I deleted the allowKeepAlive="false" (making it uses the default value of true) and all worked with big files (configuring the 'maxrequestlength' and 'maxallowedcontentlength')
As the title indicates, I recently updated an ASP.NET 3.5 application containing UpdatePanels and similar AJAX technologies to ASP.NET 4.0. Unfortunately, the UpdatePanels work no more and full page postbacks makes it all go south.
Web.config-file
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>
<system.net>
<mailSettings>
<smtp>
<network host="localhost"/>
</smtp>
</mailSettings>
</system.net>
<system.web>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" name=".ASPXFORMSAUTH" defaultUrl="~/Administration/SystemEvents.aspx"/>
</authentication>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace. -->
<customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx">
<error statusCode="401" redirect="~/Unauthorized.aspx"/>
</customErrors>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
Javascript error upon execution in Chrome:
Uncaught TypeError: Object function Function() { [native code] } has no method '_registerScript'
Uncaught TypeError: Cannot read property 'PageRequestManager' of undefined
What is there that I could've done wrong? Thank you!
Set EnablePartialRendering="false" in ScriptManager
I was having trouble with this recently as I was updating an older project and followed your steps above but it was still giving me the same error. I found that I needed to update a line in the web.config file which fixed it.
I changed:
<xhtmlConformance mode="Legacy"/>
to:
<xhtmlConformance mode="Transitional"/>
... and I've solved it myself by replacing the UpdatePanels and by removing the scripting managers.
I know this post is very old but the way I solved this problem its not given here.. So I thought its not bad to add one more way.
I tried doing
Set EnablePartialRendering="false" in ScriptManager
and it worked but then for every click the page was getting fully loaded which I didnt wanted.
so What I did is I just added a Line in Page_Load(). btnexport is button id.
ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnexport);
I first tried it outside postback but my requirements were to export even after every dropdown click which was in update panel so the button wasnt working for that.
then when I put it inside postback... voila!! It worked like a charm.
So, you can put it outside or inside postback according to your requirements.
OR
One more solution - You can do this-
You might have forgot to add trigger inside asp:updatepanel like me.
Add this inside updatepanel and voila!!
<Triggers>
<asp:PostBackTrigger ControlID="btnexport" />
</Triggers>
I'm using the Web Deployment Tool to build and release an MVC site from VS 2010 to a server running IIS. I also have log4net logging to a subdirectory off of the root of the web application I'm deploying to. I already figured out how to keep write permissions intact when deploying with this tool on that directory, but now I'm running into the problem that I'd rather not lose the logs when deploying, and also, the deploy is failing because the log file that log4net is using is "used by another process" (presumably w3wp) and won't let the deploy continue.
So, I'd like to preserve the log files and not delete or overwrite them, for auditing purposes. Is there a way to do that within the confines of the Web Deployment Tool?
EDIT: Here's the applicable bits of the log4net configuration, in Web.Config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
</configSections>
<log4net>
<appender name="RollingLog" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="20" />
<maximumFileSize value="10MB" />
<datePattern value="yyyyMMdd" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="{%level}%date{MM/dd HH:mm:ss} - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLog" />
</root>
</log4net>
</configuration>
Found it by hunting around: there is a "skip" parameter you can tack on to the command when you call the pre-packaged deploy script. You HAVE to use a regular old CMD prompt for this; Powershell's crazy escaping of quotes makes it near-impossible to get right, so I gave up. Anyway, here's the end result I came up with:
.\MyProject.deploy.cmd /Y /M:MyServerName "-skip:skipAction=Delete,objectName=filePath,absolutePath=Logs"
"MyProject.deploy.cmd" being the name of the prepackaged deploy command, "MyServerName" being the name of the server I was deploying to, and "Logs" being the name of the folder I wanted to skip. This command seems to leave alone that Logs directory and deploy anything else that matters.
Source where I started to hone in on things: http://blogs.iis.net/msdeploy/archive/2009/04/23/what-has-changed-about-skip-replace-rules-in-rc.aspx
Set locking model of your appender to minimal lock and everything will be fine:
<appender name="RollingLog" type="log4net.Appender.RollingFileAppender">
...
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
...
</appender>
log4net.Appender.FileAppender (see remarks)
I made a web.config (full file, it doesn't show XML errors)
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
...
<location path="." inheritInChildApplications="false">
<connectionStrings>
<add name="ElmahLog" connectionString="data source=~/App_Data/Error.db" />
<add name="database" connectionString="w" providerName="System.Data.EntityClient"/>
</connectionStrings>
</location>
...
with a transform file (web.Staging.config)
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="database"
connectionString="c"
providerName="System.Data.EntityClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<customErrors defaultRedirect="error.aspx"
mode="RemoteOnly" xdt:Transform="Replace">
</customErrors>
</system.web>
</configuration>
I am publishing in Staging mode (right click website > Publish > Method: File System ...)
------ Build started: Project: Drawing, Configuration: Staging Any CPU ------
Drawing -> D:\Project\bin\Staging\Drawing.dll
------ Build started: Project: MySystem, Configuration: Staging Any CPU ------
MySystem -> D:\Project\bin\Staging\MySystem.dll
...
But when I look at the web.config in the output folder it isn't changed.
I found the following on the Build log:
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
Transformed web.config using Web.Staging.config into obj\Staging\TransformWebConfig\transformed\web.config.
What could be the problem? Am I doing this right?
Answering late but perhaps I can save someone a headache. In Visual Studio 2013, there are two places to select configuration for your build and deploy. The Configuration Manager and then again with Publish Web where the third step in the Wizard entitled Settings allows you to select Config you want to use. If you don't select your new configuration it will use the transform for the selected configuration instead of yours.
I found out two things:
You cannot set a namespace on the <configuration> tag (ex: for <location path="." inheritInChildApplications="false">)
You have to watch for the correct hierarchy in the transform file.
Like
<configuration>
<location>
<connectionStrings>
Instead of
<configuration>
<connectionStrings>
Ensure that in the properties of the Web.Config file Build Action is set to Content.
If the build action is set to None, it will not be transformed, even if it is being copied to the output directory.
Make sure to include InsertIfMissing if the section you are trying to add does not already appear in the output.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<security xdt:Transform="InsertIfMissing">
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</location>
</configuration>
Don't forget to copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically and of course there will be no match...
Answering late as well, but this may help someone.
I realized that if you have two websites in the same solution, when you try to publish one of them the transformation might not work if you have one only configuration for both projects.
One of my websites was always transforming, but the other sometimes was and sometimes wasn't.
For example, I had the configuration "Auto" in the solution, and had web.Auto.config for both websites.
I resolved that by creating a new configuration with a different name - "AutoAdmin" - creating also its web.AutoAdmin.config file for the second project, and when I published it again the transformation finally occurred.
I followed the below steps to fix this issue. Thanks, #michaelhawkins for pointing in the right direction. You need to make sure you change the configuration to release in two places.
And right click on your project and select "Properties". IF not working try selecting x86 in CPU Architecture
#Karthikeyan VK your post resolved my issue. Although I was selecting Production configuration in my publish profile, in configuration manager it was set to dev therefore It didn't transform my settings.
Microsoft needs to fix this bug. Once you pick a configuration in the publishing profile it should automatically update the configuration manager as well.
I have created a simple scenario using Log4net, but it seems that my log appenders do not work because the messages are not added to the log file.
I added the following to the web.config file:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
</configSections>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="D:\MyData\Desktop\LogFile.txt" />
<appendToFile value="true" />
<encoding value="utf-8" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
Within the global ASAX file I have added:
ILog logger = LogManager.GetLogger(typeof(MvcApplication));
And within the Application_Start method:
logger.Info("Starting the application...");
Why the test log "Starting the application..." is not being added to the log file?
Do you call
log4net.Config.XmlConfigurator.Configure();
somewhere to make log4net read your configuration? E.g. in Global.asax:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// Initialize log4net.
log4net.Config.XmlConfigurator.Configure();
}
Use this FAQ page: Apache log4net Frequently Asked Questions
About 3/4 of the way down it tells you how to enable log4net debugging by using application tracing. This will tell you where your issue is.
The basics are:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>
And you see the trace in the standard output
As #AndreasPaulsson suggested, we need to configure it. I am doing the configuration in AssemblyInfo file. I specify the configuration file name here.
// Log4Net Configuration.
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
Also, Make sure the "Copy always" option is selected for [log4net].config
Make sure the process (account) that the site is running under has privileges to write to the output directory.
In IIS 7 and above this is configured on the application pool and is normally the AppPool Identity, which will not normally have permission to write to all directories.
Check your event logs (application and security) to see if any exceptions were thrown.
Insert:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
at the end of AssemblyInfo.cs file
In my case I had to give the IIS_IUSRS Read\write permission to the log file.
For me I moved the location of the logfiles and it was only when I changed the name of the file to something else it started again.
It seems if there is a logfile with the same name already existing, nothing happens.
Afterwards I rename the old file and changed the log filename in the config back again to what it was.
In my case, log4net wasn't logging properly due to having a space in my project name. Drove me nuts why the same code worked just fine in a different project, but didn't in the new one. Spaces. A simple space.
So, beware spaces in project names. I've learned my lesson.
Make sure the following line code should be there in AssemblyInfo.cs file.
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
and also check for this line in Application_start() method.
log4net.Config.XmlConfigurator.Configure();
For me I had to move Logger to a Nuget Package. Below code need to be added in NuGet package project.
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config")]
See https://gurunadhduvvuru.wordpress.com/2020/04/30/log4net-issues-when-moved-it-to-a-nuget-package/ for more details.
Your config file seems correct. Then, you have to register your Log4net config file to application. So you can use below code:
var logRepo = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepo, new FileInfo("log4net.config"));
After registering process, you can call below definition to call logger:
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
log.Error("Sample log");
There are a few ways to use log4net.
I found it is useful while I was searching for a solution. The solution is described here: https://www.hemelix.com/log4net/