Recent Comments



Ryan D
Yesterday

re: Assembly Loading across AppDomains

I've seen this issue with assembly loading across AppDomains handled by an algorithmic trading platform that I work with AlgoTerminal, www.algoterminal.com
If someone is looking to get that done, they can try to contact them for help.

They're loading trading strategies in and out of memory into separate app domains.


Sam
Yesterday

re: Accepting Raw Request Body Content in ASP.NET Core API Controllers

I'm not able to receive a json object as a string even though content-type is set to application/json. Why would this happen?

Specifically, this is happening while implementing Stripe into my ASP.NET Core API backend. Stripe takes credit card data entered by user and creates what they call a "token" which is a json object. When I send it to my API method, I'm able to hit the method but the string parameter ends up with a null value.

[HttpPost]
public async Task<IActionResult> Process([FromBody] string token)
{
   // I'm able to hit this method but end up with token=null
}

Any idea why I can't receive a json object into a string?


Fabrizio
Yesterday

re: ASP.NET Routing not working on IIS 7.0

Today, you saved my friday evening. In other projects i had to add the modules part for other libraries, in this one i didn't need and i would have never guessed the link. Thanks !


Eric
Monday

re: ASP.NET MVC Postbacks and HtmlHelper Controls ignoring Model Changes

This was SO helpful. I figured out this must be happening by hours and hours of experimentation but couldn't figure out how to confirm it. Thanks to Matt as ModelState.Clear did the trick.


Freak Power
Monday

re: .NET Core 2.0 and ASP.NET Core 2.0 are Here

Microsoft lost me with all this. .NET is a mess right now, and .NET Core makes no sense at all because MS. didn't clearly explain what is really for.


Herb
December 09, 2017

re: ASP.NET Core and CORS Gotchas

I have a weird gotcha that I haven't figured out yet. A full description can be found here. https://stackoverflow.com/questions/47731594/why-is-user-identity-isauthenticated-false-when-called-via-cors

CORS is set to enable everything.

What I am trying to do is call Signin via CORS, which would drop an auth cookie. This works, as I see that cookie being dropped. A follow up call to see if I am authenticated returns a FALSE. The call makes it to the server, but the server doesn't think I am authenticated. This doesn't happen when I make the same calls on the same domain.


Gopi V
December 06, 2017

re: Using FiddlerCore to capture HTTP Requests with .NET

Hi Rick, Is it possible to use FC (fiddler core) to pause incoming IIS requests? when PIC goes very high with cpu, I'd like to pause the incoming requests, monitor PIC to come down and let the requests get in or timeout the requets... (like IIS 6 Pause function, seems IIS 7+ removed it) If you know any 3rd party tool provides such functionality would also be useful.

Regards

Gopi


Jeff Franczak
December 02, 2017

re: Moving to Lets Encrypt SSL Certificates

Thanks Rick for taking the time to share your experience with the community. After reading this post and your other on Windows tools for Let's Encrypt, I installed Certify 2.1.27 on my AWS EC2 Server 2012 R2 instance and had an Let's Encrypt SSL certificate installed and tested in less than 15 minutes.

  • Jeff

Rick Strahl
December 01, 2017

re: Accepting Raw Request Body Content in ASP.NET Core API Controllers

@Charles - the request content type will determine how the input data is handled. If it's application/json it'll be treated as JSON, otherwise the custom handlers will pick up as a string.


Ravi Kumar Suresh Babu
December 01, 2017

re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick. I have deployed my asp net core 2 app on IIS. I am not able to see the certificates sent by the clients in https handler in aps net core app. I think I might be missing a configuration in IIS to pass the certificate to asp net core app. I have configured IIS to allow/require certificate. I have configured kestrel to allow client certificates. Can you help me with the pointers on what else could I be missing ?


Max
December 01, 2017

re: IIS and ASP.NET Core Rewrite Rules for Static Files and Html 5 Routing

I'm doing a project with Node, and this article really helped me to make everything work on nodeiis. I was finally able to make html5 routes of app play nicely with static files and API routes.

Thanks.


CharlesO
December 01, 2017

re: Accepting Raw Request Body Content in ASP.NET Core API Controllers

Hi rick,

How would you adapt this to handle a plain int posted to an endpoint?

Being that a plain int value is indeed valid JSON, i would expect the following to just work

    [HttpPost]
    [Route("reset")]
    public async Task<IActionResult> Reset([FromBody] int id)
    {
      // do something with id      
      return NoContent();
    }

Joel
November 30, 2017

re: ASP.NET Core and CORS Gotchas

Thank you for posting this. I kept bumping into the 'Gotchas'. Your post was very helpful.


Sudhakar
November 30, 2017

re: Hosting SignalR under SSL/https

Thanks Rick for the great article.

Could you please give inputs on implementing browser client side certificate verification. I mean, two way certificate verification.


Rick Strahl
November 27, 2017

re: Web Browser Control & Specifying the IE Version

@Thushara - AFAIK there's no way to set edge mode that works for all versions. At this point you probably should just force IE 11 given that it's the browser that will be used on most machines Win7 forward (via install or Windows Update).


Thushara
November 26, 2017

re: Web Browser Control & Specifying the IE Version

Even though I added it loads on IE 11 and not edge. How can we force control to use IE edge without using registry? Used below script to check the version. function Check_Version(){ var rv = -1; // Return value assumes failure.

		if (navigator.appName == 'Microsoft Internet\ Explorer'){

		   var ua = navigator.userAgent,
			   re  = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");

		   if (re.exec(ua) !== null){
			 rv = parseFloat( RegExp.$1 );
		   }
		}
		else if(navigator.appName == "Netscape"){                       
		   /// in IE 11 the navigator.appVersion says 'trident'
		   /// in Edge the navigator.appVersion does not say trident
		   if(navigator.appVersion.indexOf('Trident') === -1) rv = 12;
		   else rv = 11;
		}       

		return rv;          
	}

Maris Kurens
November 26, 2017

re: Publishing and Running ASP.NET Core Applications with IIS

Like your article The .pubxml file has elements for which we can't find any explanatory documentation. We're not sure where to set the pointers to : Does using MSDeploy still retain the FileSystem tag if we're publishing from the File System ? We don't see the DeployIisAppPath tag in your sample but we have in other previous Web Service project .pubxml files generated by MVC 3. Wrt to IIS Virtual app, do we define it as an Add Virtual Directory or Add Application ? Is Application Pool Pipeline mode Integrated or Classic ? In the VS project application settings we are using Windows output type, is that correct ? We employ C# ado.net connections to SQL Server (2016) how do we integrate that ? In short is there any resource that we can tap that maps out if not all but some of workable scenarios.


Rick Strahl
November 22, 2017

Georgi Lubomirov
November 22, 2017

re: Using Let's Encrypt with IIS on Windows

Hi,

I created a fully automated PowerShell script based on this article. It automates the process of requesting a Certificate and assigning it to an IIS Site. It can also handles renewals.

https://github.com/GLubomirov/Lets-Encrypt_Automate_PowerShell

Thanks for this article. Hope my script will help you guys too.

Have a great day, George Lubomirov


Bitupon
November 21, 2017

re: ASP.NET Core and CORS Gotchas

Hey Rick, I followed your steps but I am getting the error "Response for preflight has invalid HTTP status code 400" when I try to call an action method from an app hosted on localhost on another port. Can you please throw some light on what I am missing. Thanks.


LePatay
November 20, 2017

re: Error on 64 Bit Install of IIS – LoadLibraryEx failed on aspnet_filter.dll

Thank you so much. In my version, the bitness was set, but the "runtimeVersion4.0" was missing for the 32bit entry.

Thank you.


Rick Strahl
November 18, 2017

re: Accepting Raw Request Body Content in ASP.NET Core API Controllers

@dapug - I haven't used it but just recently discovered that this option is available. Could be useful for some things but i think I'd rather be explicit in code and decide what gets sent back.


dapug
November 17, 2017

re: Accepting Raw Request Body Content in ASP.NET Core API Controllers

Have you tried forcing a format for a POST? I know this works on a GET:

[Produces("text/plain")]

This way MVC will use the right Content-Type instead of whatever it automagically thinks is best based off the type of client.

See https://docs.microsoft.com/en-us/aspnet/core/mvc/models/formatting


Chris@CCN
November 17, 2017

re: IPad Scroll Issues with Fixed Content

THANK YOU!!!

I use Google Apps Script and have had zero success with fixed elements in their Web Apps on ios Safari. This is the ONLY solution I have found that has worked.

Was soooo close to giving up. I now feel re-energised!


Rick Strahl
November 16, 2017

re: Bootstrap Modal Dialog showing under Modal Background

@Matt - that may work in some instances but not always. I've experimented with a lot of different things and the only things that work reliably are not using a background and delay updating the z-order (out of band).


Rick Strahl
November 16, 2017

re: Dev Intersection 2017 Session Slides and Samples Posted

@Walter - no - my sessions weren't recorded.


Matt Cannon
November 16, 2017

re: Bootstrap Modal Dialog showing under Modal Background

How about just moving the modal on ngOnInit? This resolved the issue for me... I first moved it to body then realized your issue with having to remove the elements on destroy... So I just moved them to the outermost element instead, so no need to destroy...

ngOnInit() { //Move the modal by Appending it to the body otherwise it appears behind the shade $('#EditModal').appendTo('.page-content') }


Matt Cannon
November 16, 2017

re: Bootstrap Modal Dialog showing under Modal Background

How about just moving the modal on ngOnInit?

ngOnInit() { //Move the modal by Appending it to the body otherwise it appears behind the shade $('#EditModal').appendTo('body') }


Walter
November 16, 2017

re: Dev Intersection 2017 Session Slides and Samples Posted

Hi Rick

Do you know if you’re sessions videos are available to view online?


Rick Strahl
November 15, 2017

re: Publishing and Running ASP.NET Core Applications with IIS

@flipdoubt - if you're running using IIS AppOffline.htm should still work. If you use MSDEPLOY or WebPublish the using a <EnableMSDeployAppOffline>True</EnableMSDeployAppOffline> in your publish profile should do the trick in automatically doing this. I haven't tried this recently but this was working a while back. Note - the element is not in the publish file by default, so you have to manually add it in the .pubxml file.


Rick Strahl
November 15, 2017

re: Publishing and Running ASP.NET Core Applications with IIS

@Kyle - if you're using IIS in front of Kestrel you should just be able to add your certificate like you normally do in IIS. There's nothing special that has to be done. The requests are forwarded to Kestrel as plain (non-SSL requests) so that might have some effect if your code is checking for specific behavior - I believe the original URL info will be in the X- proxy forwarding headers.

FWIW, I run my sample app (https://albumviewer.west-wind.com) on IIS with a Lets Encrypt certificate, and there was nothing custom about making that work. Just install the cert to the site and off you go.

You might want to look closely on the IIS error message to see what the 404 is complaining about exactly and you can also look at the IIS request trace. Is it an IIS Error? Or is it coming from Kestrel?


Jason Beck
November 15, 2017

re: Error Handling and ExceptionFilter Dependency Injection for ASP.NET Core APIs

Rick,

I have two questions.

First, I've read that it's good to separate behavior (i.e. the handling of the exception and logging) from the attribute itself. So I created a separate class that implements IExceptionFilter, and I register that as a dependency. What are your thoughts on doing that compared to implementing the behavior within the FilterAttribute?

Second, I've found that with this technique, when calling Async methods, whether you implement inside the FilterAttribute, or in a separate behavior class, the context.Exception.StackTrace contains the TaskAwaiter calls, rather than a useful StackTrace. Have you encountered that issue with Async calls, and if so, how did you improve the logged exeption?

Thanks! Jason


Daniel
November 15, 2017

re: Accepting Raw Request Body Content with ASP.NET Web API

Hi Rick, thanks for this article. Works for me. I would like to use more than one parameter for the method besides [NakedBody].

I.e, I want to do something like this:

public string Operation([NakedBody] string body, string other, int other, ...){...}

Any way to do this? I know you stated explicitly that you can only use 1 parameter (the NakedBody parameter), but I was hoping to do something like this.

Currently if I try something like this I get the response:

{
    "Message": "The request is invalid.",
    "MessageDetail": "The parameters dictionary does not contain an entry for parameter 'body' of type 'System.String' for method 'System.String GetLicense(System.Net.Http.HttpRequestMessage, AbacusLicensingServer.Providers.ProductName, System.String, System.String)' in 'AbacusLicensingServer.Controllers.LicensingController'. The dictionary must contain an entry for each parameter, including parameters that have null values."
}

Thanks

Daniel


flipdoubt
November 13, 2017

re: Publishing and Running ASP.NET Core Applications with IIS

Rick, have you written about updating an existing site using dotnet publish? Whenever I do this, the site's files are locked by the dotnet process serving the existing site. Does Kestrel have anything like app_offline.htm that would interrupt the site so it can be updated? Can you point to any existing docs or discussion of best practices around updating an existing site?

As always, thanks.


Kyle Denney
November 13, 2017

re: Publishing and Running ASP.NET Core Applications with IIS

Hello,

I have an IIS ASP.Net Core 2 implementation setup which works fine over port 80. But the same codebase doesn't want to work with SSL and port 443. It returns a 404 given the same parameters as the port 80 site. Are there special considerations using IIS and port 443 to consider in the Program.cs or Startup.cs even if you are not securing Kestrel with SSL? Is there something else to consider other than Kestrel here? It seems like the documentation on getting SSL up and running with IIS as a reverse proxy needs further explanation and guidance.


Rick Strahl
November 12, 2017

re: Using Let's Encrypt with IIS on Windows

@Fix - Sure you can have a wildcard certificate on IIS, but Lets Encrypt does not create them. You need to use some other provider to get a wildcard certificate. According to Lets Encrypt wildcard certs are coming next year.


Fix
November 12, 2017

re: Using Let's Encrypt with IIS on Windows

Hi

Is it really (still) not possible to have one SSL certificate for multiple domain aliases / sub domains? I ask because on my Synology NAS this seems to be possible without any problem and works automatically as it should... There is an input for aliases when creating the request.

Will have a look on certify t. w. now but isn't free anmyore and doesn't even offer one time purchase!

Thx & regards


Jose Morris
November 11, 2017

re: Empty SoapActions in ASMX Web Services

Tks man!!, had the same problem and solved in a couple mins 😃


Daniel
November 09, 2017

re: Monitoring HTTP Output with Fiddler in .NET HTTP Clients and WCF Proxies

@Michael I am most certainly seeing this "run as different user" behavior and am still struggling with it actually. In a system that I do not control, I have to logon as one DOMAIN1\user1 but run an application as a different DOMAIN2\user2. The result is that Fiddler is not seeing that application's traffic!

I tried "run as different user" on Fiddler, too, but this doesn't change Fiddler's behavior to ignore traffic from that application.

Is there a way to workaround this?


Rick Strahl
November 08, 2017

re: Calling JavaScript functions in the Web Browser Control

@Michel - Yup that's because externally loaded script is not directly tied to the document. You can use document.parentWindow.MyFunctionUnknown() instead to call that. Make sure the function you call is global (ie. part of window) and that the document and script are properly and completely loaded.


Michel Laplane
November 08, 2017

re: Calling JavaScript functions in the Web Browser Control

If the Javascript function is not directly in the HTML file the function is not reachable.

<script src="library.js"></script> <script> function MyFunction() { alert("hello"); } </script>

===========in library.js

function MyFunctionUnknown()
{
  alert("hello unknown");
}

=========in C# browserControl file

webBrowser.Document.InvokeScript("MyFunction"); // Works well

webBrowser.Document.InvokeScript("MyFunctionUnknown"); // don't works

Any suggestions?

Best regards.


Rick Strahl
November 07, 2017

re: Strongly Typed Configuration Settings in ASP.NET Core

Either use DI or use a static object. The documentation has examples how to set up the singleton during application startup.

To use it then:

MyAppConfiguration.Current.SomeSettingsValue

Personally I prefer a static singleton that lives in the business layer for this and is available anywhere in the application, but you can accomplish the same with DI.


Mario
November 07, 2017

re: Strongly Typed Configuration Settings in ASP.NET Core

Hi Rick, I have the same question as Kevin. I understand that I can access the appsettings in the controller and view, but how do I access appsettings in the models? Do I have to just pass the configuration settings from the controller to my models everytime?

public IActionResult Index(int id)
{
   Person model = new Person(id); // <-- How do I pass appsetting in here?
   return View(model);
}

In this example, the person model would retrieve a user from SQL based on ID so I would like to pass in the connection string from appsettings.


Ravi
November 07, 2017

re: IIS and ASP.NET Core Rewrite Rules for Static Files and Html 5 Routing

Hi Rick,

I have one domain name for all my sites and all applications are developed in asp.net core (multiple user interface applications and a web api app). for example, https://www.example.com (I'm using an SSL cert).

I have to give the other websites different ports. So I end up with something like this:

WebSite1 - running on port 443 [https://www.example.com/ or https://www.example.com:443/]

WebSite2 - running on port 444 [https://www.example.com:444/]

WebSite3 - running on port 445 [https://www.example.com:445/]

For the end user they just want to use link as below in browser. because of port access restriction.

https://www.example.com/App1/

https://www.example.com/App2/

https://www.example.com/App3/

but server automattically identify and rewrite the url and work based on that.

https://www.example.com:443/

https://www.example.com:444/

https://www.example.com:445/

for example, If i call this link [https://www.example.com/App1/] it wants to check and rewrite with this link [https://www.example.com:443/].

How do we configure this in IIS & URL Rewriter.

Thanks in advance.


Bob
November 06, 2017

re: Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application

Hi Rick, You must hear this all the time, however this article is making my life easy! This is the first article that shows the parts needed to implement from scratch and why. I searched for hours and most search results were way into the weeds already! Thanks again! and keep on writing articles. This is not the first of yours I have read and wont be the last! Regards.


Triwaters
November 03, 2017

re: Strongly Typed Configuration Settings in ASP.NET Core

Thank you, Rick, for laying out such a nice explanation for the differences (and relative strengths and weakness) involved between IOptions and IConfiguration. I find once again that a few well-beaten (if not all) paths lead to your blog.


Tracy Dyer
November 02, 2017

re: Accepting Raw Request Body Content in ASP.NET Core API Controllers

I cannot get post methods work at all in a core 2.0 app. All get requests work fine but when I try to post anything (using any of the examples you gave) I still get a 404 ... it's driving me crazy!


Mohit Gupta
November 02, 2017

re: Web Browser Control & Specifying the IE Version

Hi Rick,

I have changed the registry key to use 11001 but still there are javascript errors showing in browser control. However these errors are not showing when I open in browser separately. It seems there are javascript ECMA6 compatible syntax like "let" "of" is not understandable by browser control and throws error. Does this registry change, enables browser control to use latest version of javascript ?

Thanks Mohit


Mahmoud Hanafy
October 31, 2017

re: Dynamically creating a Generic Type at Runtime

Thank Rick, You wrote the post on 2011, and I found it today(2017) when I needed it. I was working on a project where I needed to get an instance of a generic interface using dependency injection (Unity), and I was researching on how to dynamically provide the type parameter.

Your post pointed me right to it, using: Type elementType = typeof(keyvalue<,>).MakeGenericType(keyType, valueType);

That was very helpful, Thanks for sharing!


Marc
October 31, 2017

re: .NET Core 2.0 and ASP.NET Core 2.0 are Here

Thanks for the detailed post, Rick. You've given me the confidence to start looking at migrating some projects to .NET Core.