How do I set the maxconnection value programmatically?
This is the entry in my app.config.
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "100" />
</connectionManagement>
</system.net>
Also, how do I set throttle programmatically?
<serviceBehaviors>
<behavior name="defaultServiceBehavior">
<serviceThrottling maxConcurrentCalls="100"
maxConcurrentInstances="100" maxConcurrentSessions="100" />
I'm looking to set the same. For the first one, the below seem to fit the bill? Does that work for you?
ServicePointManager.DefaultConnectionLimit = 200;
and the below on the httpwebrequest object
webrequest.ServicePoint.ConnectionLimit = 200;
The link below shows and example of throttling programming
https://www.oreilly.com/library/view/programming-wcf-services/9780596157210/ch04s08.html
Related
I am working on Forgot Password Functionality. In my web.config file I have done the mail settings:
<system.net>
<mailSettings>
<smtp from="email">
<network host="host" port="25" userName="" password="=" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
In my SendAsync method I am trying to read setting from web.config:
SmtpClient client = new SmtpClient();
return client.SendMailAsync(ConfigurationManager.AppSettings["SupportEmailAddr"],
message.Destination,
message.Subject,
message.Body);
I have no idea what is this: AppSettings["SupportEmailAddr"]
I took this from here.
It is giving me following exception:
Value cannot be null. Parameter name: from
In your web.config file you have a section called: <appSettings>.
That is what ConfigurationManager.AppSettings is referring too.
["SupportEmailAddr"] is looking at a specific setting called SupportEmailAddr.
In your web.config it would look something like this:
<appSettings>
<add key="SupportEmailAddr" value="someone#example.com" />
</appSettings>
You are getting the value cannot be null message because you will not have the setting in your web.config as above.
So to fix the error message find your <appSettings> and add:
<add key="SupportEmailAddr" value="someone#example.com" />
Alternatively, if you have the current value in your AppSettings already then just change the key that you are looking for in the C# code.
ConfigurationManager.AppSettings["CorrectAppSettingKey"]
Note: if you plan on using any of the web.config inheritance features you should WebConfiguratonManger.AppSettings instead of ConfigurationManager.AppSettings. See the difference between the two here: What's the difference between the WebConfigurationManager and the ConfigurationManager?
We have a multi-tenanted MVC app, meaning that exactly the same app is published to multiple IIS virtual directories / applications, and then the app its self works out who it is, and skins its self (css) accordingly.
This is all very well, but anything logged by ELMAH in our elmah database gets logged under the same applicationName, as this is pulled out of Web.Config elmah section below where everything would be logged as "MyappName" :
<configuration>
[...]
<elmah>
<security allowRemoteAccess="false" />
<errorLog
type="Elmah.SqlErrorLog, Elmah"
connectionStringName="elmah"
applicationName="MyappName" />
</elmah>
</configuration>
The question is therefore how to override the applicationName setting from web.config with something specific so we can distinguish errors for a given tenant web site.
As this is configurable within the web.config, ELMAH are already providing you with a way to specify the application name when the application is deployed to different locations - it's just a case of making use of it.
This would generally be something that you would manipulate as part of your deployment steps. If you are doing it manually then it's going to be a pain, but it could be easily manipulated by using a web.config transform.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<elmah>
<errorLog applicationName="MyappName" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</elmah>
</configuration>
I wonder if the following might work, if you put the following into your Global.asax:
var service = ServiceCenter.Current;
ServiceCenter.Current = context =>
{
var connectionString = "YOUR CONNECTION STRING";
var container = new ServiceContainer(service(context));
var log = new SqlErrorLog(connectionString) { ApplicationName = "APP NAME HERE" };
container.AddService(typeof(ErrorLog), log);
return container;
};
I have the session timeout set to 20min but when I try to access this value from action I'm getting 1min instead.
Web.Config settings are:
<sessionState mode="InProc" cookieless="false" timeout="20">
<authentication mode="None">
<forms name=".ASPXAUTH" cookieless="UseCookies" timeout="20" />
</authentication>
In Global.asax.cs in Session_Start value of timeout is 20min:
HttpContext.Current.Session.Timeout
But in action in my controller is set to 1min:
System.Web.HttpContext.Current.Session.Timeout
HttpContext.Session.Timeout
I've found that when I remove SitecoreHttpModule which is of type (Sitecore.Nexus.Web.HttpModule,Sitecore.Nexus) from web.config the timeout works fine but I dont think I can remove it permanently.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
<add type="Sitecore.Web.RewriteModule, Sitecore.Kernel" name="SitecoreRewriteModule"/>
<!-- !!!REMOVED MODULE!!! <add type="Sitecore.Nexus.Web.HttpModule,Sitecore.Nexus" name="SitecoreHttpModule"/> -->
<add type="Sitecore.Resources.Media.UploadWatcher, Sitecore.Kernel" name="SitecoreUploadWatcher"/>
<add type="Sitecore.IO.XslWatcher, Sitecore.Kernel" name="SitecoreXslWatcher"/>
<add type="Sitecore.IO.LayoutWatcher, Sitecore.Kernel" name="SitecoreLayoutWatcher"/>
<add type="Sitecore.Configuration.ConfigWatcher, Sitecore.Kernel" name="SitecoreConfigWatcher"/>
...
</modules>
</system.webServer>
Is there any place I can configure this timeout for this module or there is any other way to set session timeout to desired value?
Every first request for a new user is considered as a possible bot request. That's why session timeout is set to 1 minute for those requests.
If the request is executed by the proper end user, there should be VisitorIdentification code on your page which in fact will cause another background call to the server and extend the session for the user.
Just add
#using Sitecore.Mvc.Analytics.Extensions
...
#Html.Sitecore().VisitorIdentification()
to your layout .cshtml file.
Timeout will be set to 1 minute for the first request, but then automatically changed back to 20 (or whatever is configured), when Sitecore does the VisitorIdentification call.
The problem is in robots detection in Sitecore Analytics module. My browser is recognized as a bot and there are some settings about that in Sitecore.Analytics.Tracking.config file:
<!-- ANALYTICS ROBOTS SESSION TIMEOUT
The ASP.NET Session Timeout for auto detected robots.
When the automatic robot detection identifies a session as being a robot, the ASP.NET
Session Timeout is set to this value (in minutes).
Default: 1
-->
<setting name="Analytics.Robots.SessionTimeout" value="1" />
The timeout is set to 1min when bot is detected to save some mememory and not to keep session too long.
The timeout will be set to desired 20min value when I either disable Analytics at all or disable Analytics.AutoDetectBots (in Sitecore.Analytics.Tracking.config file).
The proper solution for this is to clasify browser correctly (not as a bot).
Another post on this issue:
Sitecore Analytics Robots SessionTimeout causing premature session timeout
In Sitecore 7 there is now multiple places you have to specify the Session Timeout.
I would check these values in your Web.config.
<setting name="Authentication.ClientSessionTimeout" value="120" />
and
<forms name=".ASPXAUTH" cookieless="UseCookies" timeout="120" />
and then
<sessionState mode="InProc" ... timeout="120" />
More info here:
Strange Timeout in Sitecore 7
I'm using Examine to search in website content,
But whenever an article is updated, it is shown more than once in the result, with same count as the number of modifications !!
<IndexSet SetName ="ArabicIndexerIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Arabic/">
<IndexUserFields>
<add Name="id" EnableSorting="true" Type="Number" />
<add Name="content" EnableSorting="true" />
<add Name="author" EnableSorting="true" />
<add Name="title" EnableSorting="true" />
<add Name="description" EnableSorting="true" />
<add Name ="umbracoNaviHide"/>
</IndexUserFields>
</IndexSet>
<ExamineSearchProviders defaultProvider="ArabicSearcher">
<providers>
<add name="ArabicSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
indexSet="ArabicIndexerIndexSet"
supportUnpublished="false"
supportProtected="false"
analyzer="Lucene.Net.Analysis.AR.ArabicAnalyzer, Lucene.Net.Contrib.Analyzers"/>
</providers>
</ExamineSearchProviders>
and this is my query:
+((title:Test Phrase content:Test Phrase)) +(umbracoNaviHide:0)
How to solve this?
EDIT:
Rebuilding the index solves the problem temporarily, and once you modify the article again, the problem appears again.
EDIT2:
I used Luke to investigate the problem, the only difference is the update date between the duplicated results.
See the image:
EDIT3:
I found a solution that worked, but I'm not convinced with it here: Index is not updated automatically
which suggests to use the follwing code:
public class UmbracoEvents: ApplicationBase
{
/// <summary>Constructor</summary>
public UmbracoEvents()
{
umbraco.content.AfterUpdateDocumentCache += new umbraco.content.DocumentCacheEventHandler(content_AfterUpdateDocumentCache);
}
privatevoid content_AfterUpdateDocumentCache(Document sender, umbraco.cms.businesslogic.DocumentCacheEventArgs e)
{
// Rebuild SiteSearchIndexer (Search results will be updated after a few minutes)
ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].RebuildIndex();
}
}
The problem with this solution is that it takes a long time to rebuild the index with large amount of content! (10000 documents in my case) and during the index rebuild process, the user will get 0 result searching anything, which confuses the user.
It looks like your search query is incorrectly structured. If you are searching for the phrase "Test Phrase" in the title and content property, your query should be:
+(title:Test Phrase content:Test Phrase) +(umbracoNaviHide:0)
I've been searching for info on how to disable client side caching on project level.
I know I can add the following before an action method:
[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
I also read something about making profiles for caching, but that would also mean refering to them in several places. I would like a single setting in web.config, or maybe in IIS?
The project I'm working on contains a lot of partial views
Thank you in advance for any advice in this matter.
You can disable browser caching via Web.Config:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache, no-store" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Source: http://blog.jamesjones.name/2009/11/how-to-disable-browser-caching-in.html
Edit: added no-store to Cache-Control for Chrome ( http://code.google.com/p/chromium/issues/detail?id=28035 )
You can set this at the project level or at the subdirectory level to control browser caching as desired. For example, in a primarily data-driven/dynamic site, I may set these headers at the project level, but in a /static directory (which contains my .js, .css, images), add another web.config which includes the appropriate </clear> directive, and perhaps set a far-future-expires header instead.
You could make BaseController and set your cache profile to it.
Then make all of your controllers to inherit from this BaseController.
Update:
Here is what I've :
// Here is my custom OutputCaheAttribute to prevent cache at all.
//Whatever you may put anything you want.
//Of course i don't use it here but i put it to show you how it's going.
[NoCache]
public class BaseController : Controller
{
protected override ViewResult View(string viewName, string masterName, object model)
{
// I do some stuffs here to change MasterPage depending on current culture.
// Don't care about it i just wanna show you why BaseController is good idea.
}
}
Then ALL my controllers inherits from this BaseController instead of normal Controller.
Hope this was helpful ;)
Expanding on #Tom's answer, for per file or per directory based cache busting :
<configuration>
<!-- disable cache for every file in this directory -->
<location path="dist">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
You can define cache profiles in web.config, however, using cache profiles doesn't seem to work with OutputCache attribute in mvc 3. Read this question: Caching ChildActions using cache profiles won't work?
The OutputCache attribute is used for server side output action output caching. To turn it off, you just don't apply the attribute to the action/controller. If you want to disable client side, then that is taken care of by adding a header informing the browser not to cache the result.
If you need to cache files in a subfolder for 1 day (24 hours), you can add a separate web.config to these sub folders (requires clearing client cache the first time).
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:24:00" />
</staticContent>
</system.webServer>
</configuration>
Try this
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]