﻿<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://developers.de/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Holger's Blog : ASP.NET</title><link />http://developers.de/blogs/holger_vetter/archive/tags/ASP.NET/default.aspx<description>Tags: ASP.NET</description><dc:language>en</dc:language><generator>CommunityServer 2008 SP1 (Build: 30619.63)</generator><item><title>Identify ASP.Net Core startup errors</title><link />http://developers.de/blogs/holger_vetter/archive/2016/11/30/identify-asp-net-core-startup-errors.aspx<pubdate>Wed, 30 Nov 2016 15:31:00 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1803047</guid><dc:creator>Holger Vetter</dc:creator><slash:comments>9</slash:comments><wfw:commentrss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://developers.de/blogs/holger_vetter/rsscomments.aspx?PostID=1803047</wfw:commentrss><comments>http://developers.de/blogs/holger_vetter/archive/2016/11/30/identify-asp-net-core-startup-errors.aspx#comments</comments><description>&lt;p&gt;Maybe you know this great and informative error message &amp;quot;An error occurred while starting the application.&amp;quot; from asp.net core when there was an exception during the startup.
&lt;/p&gt;
&lt;p&gt;&lt;img src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/holger_5F00_vetter/113016_5F00_1531_5F00_IdentifyASP1.png" alt="" /&gt;
	&lt;/p&gt;
&lt;p&gt;To identify and understand what happened, you must extend the Main method with the following things:
&lt;/p&gt;
&lt;p&gt;&lt;img src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/holger_5F00_vetter/113016_5F00_1531_5F00_IdentifyASP2.png" alt="" /&gt;
	&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;UseSetting(&amp;quot;detailedErrors&amp;quot;, &amp;quot;true&amp;quot;)
&lt;/li&gt;
&lt;li&gt;CaptureStartupErrors(true)
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After this is done, you will see a nice and detailed error page like this:
&lt;/p&gt;
&lt;p&gt;&lt;img src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/holger_5F00_vetter/113016_5F00_1531_5F00_IdentifyASP3.png" alt="" /&gt;
	&lt;/p&gt;
&lt;p&gt;In my case the startup error was a missing json file which the application tried to load on startup.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1803047" width="1" height="1"&gt;</description><category domain="http://developers.de/blogs/holger_vetter/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://developers.de/blogs/holger_vetter/archive/tags/Core.Net/default.aspx">Core.Net</category></item><item><title>ASP.NET Core returns StatusCode:500</title><link />http://developers.de/blogs/holger_vetter/archive/2016/11/10/asp-net-core-returns-statuscode-500.aspx<pubdate>Thu, 10 Nov 2016 12:56:24 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1802216</guid><dc:creator>Holger Vetter</dc:creator><slash:comments>0</slash:comments><wfw:commentrss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://developers.de/blogs/holger_vetter/rsscomments.aspx?PostID=1802216</wfw:commentrss><comments>http://developers.de/blogs/holger_vetter/archive/2016/11/10/asp-net-core-returns-statuscode-500.aspx#comments</comments><description>&lt;p&gt;I ported an MVC WEB API project to ASP.NET Core and now the Service just returned StatusCode: 500 every time I called it.
&lt;/p&gt;&lt;p&gt;Visual Studio doesn&amp;#39;t give me any information or Exception to indicate what happened. 
&lt;/p&gt;&lt;p&gt;To find the error I disabled &amp;quot;Enable just my Code&amp;quot; in the visual studio settings.
&lt;/p&gt;&lt;p&gt;&lt;img src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/holger_5F00_vetter/111016_5F00_1328_5F00_ASPNETCorer1.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;Now the visual studio showed this exception from the framework, when I call the service:&lt;br /&gt;&amp;quot;Multiple constructors accepting all given argument types have been found in type &amp;quot;…&amp;quot;. There should only be one applicable constructor&amp;quot;.
&lt;/p&gt;&lt;p&gt;&lt;img src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/holger_5F00_vetter/111016_5F00_1328_5F00_ASPNETCorer2.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;&lt;img src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/holger_5F00_vetter/111016_5F00_1328_5F00_ASPNETCorer3.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;This error indicates that we have multiple constructors, which accepts same argument types. But this wasn&amp;#39;t the case, I just removed the empty constructor and it worked fine.
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;&lt;img src="http://developers.de/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/holger_5F00_vetter/111016_5F00_1328_5F00_ASPNETCorer4.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;One was the empty constructor I had before in my ASP.NET WEB API application and the other one was for ASP.NET Core.&lt;br /&gt;I just removed the empty one and it worked fine &lt;span style="font-family:Wingdings;"&gt;J&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;Recap: Don&amp;#39;t use multiple constructors when injection IOptions.
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1802216" width="1" height="1"&gt;</description><category domain="http://developers.de/blogs/holger_vetter/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://developers.de/blogs/holger_vetter/archive/tags/Core.Net/default.aspx">Core.Net</category></item><item><title>ASP.NET MVC WEB API Impersonation Thread issue</title><link />http://developers.de/blogs/holger_vetter/archive/2016/09/20/asp-net-mvc-web-api-impersonation-thread-issue.aspx<pubdate>Tue, 20 Sep 2016 14:53:00 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1798852</guid><dc:creator>Holger Vetter</dc:creator><slash:comments>0</slash:comments><wfw:commentrss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://developers.de/blogs/holger_vetter/rsscomments.aspx?PostID=1798852</wfw:commentrss><comments>http://developers.de/blogs/holger_vetter/archive/2016/09/20/asp-net-mvc-web-api-impersonation-thread-issue.aspx#comments</comments><description>&lt;p&gt;In an ASP.NET MVC WEB API application I implemented Windows Authentication with custom roles by using an implementation of IIdentity.   &lt;br /&gt;In my setup the user gets authenticated by NTLM, then we have the user name. Now there is a part in the OWIN Pipeline which gets the roles for this user and caches them.&lt;/p&gt;
&lt;p&gt;When the user sends a request to the server it will go trough the &amp;ldquo;Application_OnPostAuthenticateRequest&amp;ldquo;method in the Global.asax.cs, this method will then get the User from the current thread (which is the authenticated user) and then create a new object of our custom implementation of IIdentity. After this we map some things like the UserName and get the correct roles for this user and append them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;The important part in the &amp;ldquo;Application_OnPostAuthenticateRequest&amp;rdquo; method is to set the modified Thread.CurrentPrincipal back to the HttpContext.Current.User. If you don&amp;rsquo;t do this, you possible lose our custom Identity object next time ASP.NET maps/sets the HttpContext.Current.User&amp;nbsp;to Thread.CurrentPrincipal (Thread.CurrentPrincipal gets overriden by HttpContext.Current.User).&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In my tests the ManagedThreadId in OnPostRequest method and the actual service operations where different, but not everytime. When I attach a debugger it worked. This leaded me to a threading problem. In the OnPostRequest method I set the Thread.CurrentUser and in my service operation I was in a different thread, that&amp;rsquo;s why the custom roles disappeared.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Maybe you have the some problem and this helps you :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1798852" width="1" height="1"&gt;</description><category domain="http://developers.de/blogs/holger_vetter/archive/tags/.NET/default.aspx">.NET</category><category domain="http://developers.de/blogs/holger_vetter/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://developers.de/blogs/holger_vetter/archive/tags/WEB+API/default.aspx">WEB API</category></item></channel></rss>