OutDir vs OutputPath for Visual studio 2015 and Asp.Net Core


In MSBuild for Asp.Net Core use /p:OutputPath parameter, not /p:OutDir nor both.

Full story

We’ve used psake powershell build for ASP.Net 4.61 project and passed both parameters
msbuild  /p:OutDir=“$binariesDir\” /p:OutputPath=“$outPath\”
Actually /p:OutputPath was ignored(almost, see below) and build was saved to specified in /p:OutDir folder.
When I included Asp.Net Core project into solution, it’s failed because dll, referenced by the Core project, was saved to OutDir folder, but Asp.Net Core project tried to find it in OutputPath folder.
I’ve tried to remove /p:OutputPath  parameter (as suggested in OutputPath vs OutDir thread: “to keep the OutputPath that is generated by Visual Studio, then set the OutDir as a command argument”), Asp.Net Core project failed because dll was saved to OutDir folder, but Asp.Net Core project tried to find it in relative bin\Release\ folder.
When I removed OutDir parameter and specified /p:OutputPath=“$binariesDir\” build was successful,  but package for MSDeploy, specified in a custom MS Build step, was created in a relative path obj\Release\Package rather than specified $binariesDir folder, so I needed to adjust package path.
Current VS 2015 MSDN page  Common MSBuild Project Properties doesn’t document OutDir , but only OutputPath.
Note that previously MSDN recommended the opposite: “OutputPath has been deprecated and OutDir should be used instead whenever possible. ”

ScrollToControl helper method for ASP.Net web forms to move position to particular control

I’ve created a helper method for ASP.Net web forms to move position to particular control
            /// <summary>
            /// </summary>
            /// <param name=”page”></param>
            /// <param name=”clientId”></param>
            /// <param name=”alignToTop”></param>
            public static void ScrollToControl( Page page, string clientId, bool alignToTop)
                //NOTE: if there are more than one call on the page, first one will take preference
                //If we want that last will take  preference, change key from MethodBase.GetCurrentMethod().Name to anchorName
                //recommended in http://gnidesign.blogspot.com.au/2011/06/how-to-maintain-page-scroll-on-postback.html               
                String script = ” window.scrollTo = function () { };” + Environment.NewLine;
                script += String.Format(“document.getElementById(‘{0}’).scrollIntoView({1});” , clientId, alignToTop.JSToString());
                page.ClientScript.RegisterStartupScript(TypeForClientScript(), MethodBase.GetCurrentMethod().Name, script, true );
                //return script;
            public static string JSToString(this bool bValue)
                return bValue.ToString().ToLower();

Use getElementById(‘{0}’).scrollIntoView is simpler than location.hash , because you don’t need to add extra anchor element.
Parameter alignToTop is very convenient to specify do you want to show control at the top or bottom of the screen.

It’s posted as an answer http://stackoverflow.com/a/34823392/52277
There is more advance jQuery plug-in http://erraticdev.blogspot.com.au/2011/02/jquery-scroll-into-view-plugin-with.html

Tiny MCE editor in ASP.Net Web Form

I wanted to implement rich text editor in ASP.Net Web Form. I found that Tiny MCE editor is very popular and selected it.

Response for REST method was truncated because default MaxItemsInObjectGraph was not big enough.

We have a   REST service with attributes [WebGet(UriTemplate =“…”, BodyStyle =WebMessageBodyStyle.Bare, ResponseFormat =WebMessageFormat.Xml)]

Normally it worked fine. But for particular data it has a huge response that was truncated. 

The size returned in a few attempts in IE browser was 2196456, in Chrome slightly different 2195397.

After a search in google I found http://forums.asp.net/post/4948029.aspx, that has a number of suggestions.


For WCF service that will transfer large amount of data in operations, here are the configuration settings you need to check:

1) the maxReceivedMessageSize attribute of the certain <binding> element(in your case, that’s the webHttpbinding)


2) The <readerQuotas> settings (under the <binding> elements) which has control over the maxarrayLength, maxStringLength ,etc…


3) The DataContractSerializer behavior which has a MaxItemsInObjectGraph property. You can configure it via ServiceBehavior of your WCF service

#DataContractSerializer.MaxItemsInObjectGraph Property 

4) And if your WCF service is hosted in ASP.NET/IIS web application, you also need to enlarge the “maxRequestLength” attribute of the <httpRuntime> element (under <system.web> section).

#httpRuntime Element (ASP.NET Settings Schema) 

 After a few attempts my collegue found that our problem was caused by

#DataContractSerializer.MaxItemsInObjectGraph Property 


<behavior name=“MyOperationBehavior>
          < dataContractSerializer maxItemsInObjectGraph =2196456 />

Missing error handling in Streaming-AJAX-Proxy Log

on our web site, but started to notice errors accessing log.txt file.
I found that the file is created by Log class and doesn’t have ability to switch it off and error handling.
I’ve added reading file name from configuration and try/catch block
  public static class Log
        private static StreamWriter logStream;
        private static object lockObject = new object ();
    public static void WriteLine(string msg)
                      string logFileName = ConfigurationExtensions.GetAppSetting(“AjaxStreamingProxy.LogFile” ,“”);
                      if (logFileName.IsNullOrEmpty())
                            if (logStream == null )
                                   lock (lockObject)
                                          if (logStream == null )
                           logStream = File.AppendText(Path .Combine(AppDomain.CurrentDomain.BaseDirectory, logFileName));
                      catch (Exception exc)
                            string ignoredMsg = String .Format(“The error occured while logging {0}, but processing will continue.n {1} , exc);
                            LoggerHelper.LogEvent(ignoredMsg, MyCategorySource, TraceEventType .Warning, true);

Adding Async=true to the page- no side effects noticed.

Recently I needed to implement PageAsyncTask  in .Net 4 web forms application.

“A PageAsyncTask object must be registered to the page through the RegisterAsyncTask method. The page itself does not have to be processed asynchronously to execute asynchronous tasks. You can set the Async attribute to either true (as shown in the following code example) or false on the page directive and the asynchronous tasks will still be processed asynchronously:

<%@ Page Async=”true” %>

When the Async attribute is set to false, the thread that executes the page will be blocked until all asynchronous tasks are complete.”

I was worry about any site effects if I will set  Async=true on the existing page.
The only documented restrictions, that I found are that

@Async is not compatible with @AspCompat and Transaction attributes (from @ Page directive  MSDN article). In other words, 

Asynchronous pages do not work when the AspCompat attribute is set to true or the Transactionattribute is set to a value other than Disabled in the @ Page directive

From our tests we conclude, that adding Async=true to the page is quite safe, even if you don’t always call Async tasks from the page 

Configuration setting of HttpWebRequest.Timeout value

I wanted to set in configuration on client HttpWebRequest.Timeout.
I was surprised, that MS doesn’t provide it as a part of .Net configuration.
(Answer in http://forums.silverlight.net/post/77818.aspx thread: “Unfortunately specifying the timeout is not supported in current version. We may support it in the future release.”)
I added it to appSettings section of app.config and read it in the method of My HttpWebRequestHelper class

  //The Method property can be set to any of the HTTP 1.1 protocol verbs: GET, HEAD, POST, PUT, DELETE, TRACE, or OPTIONS.
       public static
HttpWebRequest PrepareWebRequest(string sUrl, string Method, CookieContainer cntnrCookies)
HttpWebRequest webRequest = WebRequest.Create(sUrl) as HttpWebRequest;
           webRequest.Method = Method;
           webRequest.ContentType =
           webRequest.CookieContainer = cntnrCookies;
webRequest.Timeout = ConfigurationExtensions.GetAppSetting(“HttpWebRequest.Timeout”, 100000);
//default 100sec-http://blogs.msdn.com/b/buckh/archive/2005/02/01/365127.aspx)
           /*                //try to change – from http://www.codeproject.com/csharp/ClientTicket_MSNP9.asp          
                       webRequest.AllowAutoRedirect = false;
                      webRequest.Pipelined = false;
                       webRequest.KeepAlive = false;
                       webRequest.ProtocolVersion = new Version(1,0);//protocol 1.0 works better that 1.1 ??
           //MNF 26/5/2005 Some web servers expect UserAgent to be specified
           //so let’s say it’s IE6
           webRequest.UserAgent =
“Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)”;

DebugOutputHelper.PrintHttpWebRequest(webRequest, TraceOutputHelper.LineWithTrace(“”));
           return webRequest;

Related link: