Recent Comments



Martin S.
Wednesday

re: Creating Single Instance WPF Applications that open multiple Files

In Debug, the code from below will show:
"App"
"OnStartup"

Running the installed App shows:
"OnStartup"
"App"

public partial class App : Application
{
    public App()
    {
        MessageBox.Show("App");
    }

    protected override void OnStartup(StartupEventArgs e)
    {
        MessageBox.Show("OnStartup");
    }
}

The own constructor doesn't seem to be the "real" constructor:
https://stackoverflow.com/questions/41422975/what-is-the-difference-between-app-constructor-and-app-onstartup


Rick Strahl
Wednesday

re: Excluding the node_modules Folder in Visual Studio WebSite Projects

@yaron - I hope not πŸ˜ƒ If you have a node_modules folder you'll want to build your project and not ship the huge amount of content in there, only the bundled and built content. If you build using CI on the server, then you shouldn't send that folder at all but do the NPM restore on the server.


yaron
Wednesday

re: Excluding the node_modules Folder in Visual Studio WebSite Projects

in this case how are node_modules published? aren't they needed in the runtime env?


Alexey Kulakov
Tuesday

re: Forms Auth loginUrl not working after Windows Update?

Same problem on brand new Windows Server 2019 and IIS 10. Nothing has changed since then. Maybe i'm not aware of some setting of ISS but I don't have to. Tweaking such things while moving a website from one server to another is kind of annoying. Huge thanks to the author for the post and saving my day.


Amey
May 20, 2019

re: Easy Configuration Binding in ASP.NET Core - revisited

Hi Rick,

I'm still learning new dot net core stuff. All these settings in startup and program class in asp.net app still perplexing task. Your post saved my day.

Thank you Rick πŸ˜ƒ


Janus Knudsen
May 17, 2019

re: Strongly Typed Configuration Settings in ASP.NET Core

Old post, but I really don't see the point in using IOptions unless you're developing a library of some sort and then utilize the PostConfig-feature.

Why would we ever rely on injection IOptions? Especially when we just need the value, which we easily and more obviously could get directly from a strong typed/ GetSection.

IMHO The Reload-feature could as easily just be handled by a simple db-setting/ adjust via query string for flexibility, I think this would be more readable and easier to maintain.

Anyway.. it is always nice to have some tools in the box πŸ˜ƒ Have a great day Rick.


Gerke Geurts
May 16, 2019

re: Accessing RouteData in an ASP.NET Core Controller Constructor

I had the same problem, accessing the tenant ID from route data in custom middleware, and found the answer in https://stackoverflow.com/questions/38505184/asp-net-core-get-routedata-value-from-url. It is possible to initialize the route data early on in the pipeline.


William McGray
May 14, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2

@Rick, very well explained and thank you for this article. Actually, I just want to test this new .net core project on my hosting provider. I use .net 4.5 on my site. On new project, I plan to use new .net core on my hosting since my provider has support .net core. So, this article really helpful.

@Gary, With your budget around Β£5 per month, just use my hosting provider, asphostportal.com. So far, they are good and really stable. Or second option for you is hostforlife.eu, it is also worth for money. Hope it helps!


Dima K
May 14, 2019

re: Which .NET Core Runtime Download do you need?

Thank You for this post "Note the info icons ..." - they should have highlighted those with big red exclamation marks ...


Armand
May 14, 2019

re: Using the ng-BootStrap TypeAhead Control with Dynamic Data

Hi There,

Very nice explanation, also took my some time to figure out what is going on with this thing, but got it working mostly.

I have an issue now, my observable that I use for the results is updated externally, thus when a user types something, the request is sent to the server by tapping into the pipe and then using a switchMap on that returns my observable, but this observable comes from outside of my component, the function I call that does the web request also lives outside of my component.

What this is causing is that user might search a name and the http request returns a result, but the result is only shown when the user types another key, do you have any idea of how I can force the ngbtypeahead to update the results shown on screen?

Thanks


Rick Strahl
May 13, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2

@Andrew - I haven't checked that and not actually sure whether that is supported. I suspect it isn't. Is that really necessary though? Do you really need to run in process while debugging?


Andrew Robinson
May 13, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2

Rick, I have inprocess working fine but when running this way, I am unable to debug my app. Simple breakpoints fail to break. If I turn the hosting model settings under the project debug settings to "Out of Process" then my breakpoints start working. It wasn't clear to me from your write up that this is the behavior everyone should be seeing. Any help or pointer in the right direction would be appreciated. Thanks for the write up.


Rick Strahl
May 11, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2

@Sumit - Yes you'll want it so you can still run out of process or during development if you don't want to use IIS or IIS Express or you run on a non-windows platform.

ASP.NET Core will do the right thing once the server starts to figure out which server it needs to run. Those references are included in the runtime dependencies anyway so you're not gaining anything by removing them.


Sumit
May 11, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2

Hi Rick, thanks for such a nice post. Everything is very well explained. Just want to ask you that, as we all know that CreateWebHostBuilder method internally calls UserKesteral method so my question is that do we need that method when we use InProcess hosting?


Rick Strahl
May 11, 2019

re: ASP.NET Core and CORS Gotchas

I think the API changed recently and you now need to use SetIsOriginAllowed(). I seem to recall recently that AllowAnyOrigin() no longer worked.

services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                    builder => builder
                            // required if AllowCredentials is set also
                        .SetIsOriginAllowed(s=> true)
                        //.AllowAnyOrigin()             
                        .AllowAnyMethod()
                        .AllowAnyHeader()                            
                        .AllowCredentials()
                    );
            });

John Dover
May 10, 2019

re: ASP.NET Core and CORS Gotchas

Rick I have always enjoyed reading your articles! I like how you are able to take a 'specific' topic and make it easy to understand. With that being said, I have issues with CORS and windows authentication. I recently started developing using Vue.js as my client using axios for requests to api. Following your example above I am still not able to hit my api method from my client. Here is a snippet from client calling api. I have tried to include 'withCredentials', or not including any headers at all, but nothing seems to work

      this.$http.get("http://localhost:58460/api/values", {
          
      headers: {
         //'Content-type': 'application/json',
           'withCredentials': true
         //'Bearer': ' ' + this.token
      }})
      .then(response => this.currentUser = response.data)
      .catch(err => console.log(err));

and in my Values controller

    [Route("api/Values")]
    [ApiController]
    //[EnableCors("CorsPolicy")]
    public class ValuesController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        [Authorize (AuthenticationSchemes = "Windows")]
        public ActionResult<string> Get()
        {
            return this.HttpContext.User.Identity.Name;
        }
    }

and lastly my Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                builder =>
                {
                    builder
                    //.WithOrigins("http://localhost:8081", "https://localhost:8081")
                    .AllowAnyOrigin()
                                        .AllowAnyHeader()
                                        .AllowCredentials()
                                        .AllowAnyMethod();
                });
            });
            services.AddAuthentication(IISDefaults.AuthenticationScheme);
            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            app.UseCors("CorsPolicy");
            app.UseHttpsRedirection();
            app.UseMvc();
        }

with this in place I still receive a 401 unauthorized when trying to access my api. Do you have any suggestions on how to make this work? I have been struggling with this for 2 days now, and at my wits end. Any help is appreciated. I know that this is not SO, but thought your experience might help. Thanks!


Musti
May 10, 2019

re: Creating a custom HttpInterceptor to handle 'withCredentials' in Angular 6+

Hello Rick, what is the proper way to register the Interceptor for a HttpClient that is not injected in the constructor but initialized by an injector service? Many thanks for listening and your answer in advance.


Sam
May 08, 2019

re: Configuring LetsEncrypt for ASP.NET Core and IIS

How would you handle the case when you have Https Redirection, i.e. app.UseHsts(); and app.UseHttpsRedirection(); in Startup.cs? If it is a sub application in a site, i.e. mydomain.com/myapp that may have a HTTPS redirect set up on it in the web.config.


Roger
May 06, 2019

re: Getting JavaScript Properties for Object Maps by Index or Name

Thank you ! Spent hours on this before reading your article: Only worthwhile resource on the Web. Awesome.


Dan Narsavage
May 06, 2019

re: Adventures in .NET Core SDK Installation: Missing SDKs and 32 bit vs 64 bit

Thanks for this great write-up! FWIW, I had to uninstall ALL x86 versions of the SDK & runtime before ANY x64 stuff would show up in the CLI.


Max
May 05, 2019

re: Debouncing and Throttling Dispatcher Events

Hi Rick

First off, big fan of your blog, been following your asp.net comments many times πŸ˜ƒ

I have to say this is a good classic debounce approach - one we used to take before we started using Angular and RxJs several years back. Today, we like to use Rx in C# too, because our programming team is very familiar with the Rx concepts, it's also surprisingly small in implementation.

I just wanted to share with you and example of keystroke debounce on a classic key up from a Windows Forms app (just as easy in WPF to do too). but wanted to illustrate πŸ˜ƒ- it relies on outputting the event values to a behavior subject, that passes them to an observable that we then debounce.

Add this above the constructor of your form (or user control):

private BehaviorSubject<KeyEventArgs> _oFilterKeysBS = new BehaviorSubject<KeyEventArgs>(null); // will fire a null initially.

Add this in the constructor of your form (or user control):

// get the filter keys as observable and debounce.
_oFilterKeysBS.AsObservable().Throttle(TimeSpan.FromMilliseconds(500)).Subscribe(
	(e) => {
		if (e == null) return; // initialization (ignore)
		this.BeginInvoke((Action)(() =>
		{
			// execute code on the UI thread. Classic Windows Forms.
			// ex: use the filter text to filter the data
		}));
	},
	(ex) => { Console.WriteLine("Got exception: "+ex.Message); } , // optional
	() => { Console.WriteLine("Completed"); } // optional
);

And then feed the behavior subject from your classic .net event handler, there are other methods, but I find them too verbose:

private void tb_Filter_KeyUp(object sender, KeyEventArgs e)
{
	// output the key event to the Behavior Subject, will which fire the observable.
	_oFilterKeysBS.OnNext(e);
}

Then maybe I'll see you on the water some time in Hood River. But I tend to stay at the coast.

Cheers


Ray Simpson
May 03, 2019

re: .NET Standard 2.0 - Making Sense of .NET Again

Hey Rick,

I just wanted to thank you for years of help. I started my IT career in the late 90's and I have been to your blog many many times and it has saved my bacon just about every time. I just wanted to let you know that if your ever in AZ let me know, I owe you a few beers πŸ˜‰

Ray Simpson


Alex Roosvelt Douglas Quispe Cuadros
May 02, 2019

re: LINQ To SQL and the Web.Config ConnectionString Value

Thank You, the information is very good


Rick Strahl
May 02, 2019

re: .NET Core 3.0 SDK Projects: Controlling Output Folders and Content

Yeah I see that even in this smaller project - however I can't get a project reference to output the right things in the output folder so for now I don't have a better solution unfortunately.


Ruslan
May 01, 2019

re: .NET Core 3.0 SDK Projects: Controlling Output Folders and Content

Hi! I would not recommend to use Assembly Reference instead of Project Reference because of parallel builds of solution. E.g. if you has huge solution with ~100 projects and some of projects use Assembly Reference it can raise exceptions on build when that project is builded before referenced one. It can be randomly. So need to tune Project Dependencies in this case or avoid Assembly Reference.


Matt
May 01, 2019

re: Working around the lack of dynamic DbProviderFactory loading in .NET Core

Hi Rick - I think your prayers have been heard.

DbProviderFactories appears to be alive and well in .NET Core 2.2


Artur M.
May 01, 2019

re: .NET Core 3.0 SDK Projects: Controlling Output Folders and Content

Hi. This is a great and very helpful post! One question, if you don't mind: in those Explorer-like screenshots, what program are you using? Thanks.


Rick Strahl
April 27, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

@Scott - I was considering CefSharp for a while. I have a few examples going with it but for WPF CefSharp is problematic. They do render then draw an image which is in effect very slow for the WPF control. You can use the WinForms control and that's faster but a bit ugly to hook in and I'm not sure about stability. The other issue is that adding Chromium in any for this way will add 20 meg payload to the app which also sucks. IOW - it would double the size of MM just for the new browser control.

The other issue I had been struggling with was that I code to the COM control specifically and changing over would be a fairly big job. Over the last few days though I took a bit of time to isolate all the COM interop calls into a separate class and with that I should be able to more easily port going forward. Basically any interop call is explicitly wrapped with an intermediate method. I switched this interface to use raw Reflection so in theory this will get around the problem I describe in the article.

Re: CefSharp - at this point I'm pretty sure I have to ditch the IE control because there are rendering issue for some support controls. I'm going to wait however and see how the Edge Chromium integration works out. Supposedly there will be an updated WebView control that will be accessible from WPF. The big question will be how well (if at all) you can interop with that control. I expect that interface to be similar to the Edge interface of the WebView which unfortunately was pretty terrible (plus no support for loading disk resources natively as a URL - you needed to write an explicit file handler which seemed really dumb given the uses cases that an embedded Web Browser is meant to address).

So yeah - it keeps me awake at night too πŸ˜ƒ What I heard at the Summit this year from talking with some of the Edge folks sounded pretty promising though, although they often promise a lot and don't follow through. We'll see.


Scott G.
April 27, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

Hi Rick, I've been following your WPF/MM posts since you started. I maintain a large WPF app at work and use the embedded Web control - and of all the things that have caused me angst over the years it's that thing - but I just can't live without it.

Do you think it's time to revisit using Cef for Core 3?


Daniel
April 26, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

hi Rick, have you tried different Tiered Compilation settings to improve startup time in .NET Core 3.0 ?


Vatsan Madhavan
April 26, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

I just heard from a colleague a day ago that they finished the work to enable crossgen for WindowsDesktop.App and that the updated bits with preview6 branding are already flowing into github.com/dotnet/core-sdk. Crossgen happens after the bits leave dotnet/wpf, btw. I haven’t had a chance to play with these yet, but I’d expect significant startup time improvements.

I think you may even be able to try it out at an app level today, though it’s likely still experimental


Rick Strahl
April 26, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

@Alberto - everytime I post something about WPF this comes up not surprisingly.

If you want to build a commercial quality Electron app you have a lot of work ahead of you building a professional desktop UI. Although there are lots of Web frameworks out there to help with UI design for Web sites, I haven't seen anything that is specifically tailored to desktop UIs. Take a close look at VS Code and realize that all that UI - the custom tabs, the menus, the tree - all that stuff is hand built. if you build your own desktop app with Electron you'll end up building a lot of UI components to make that work well. VS Code is OSS so you could potentially lift a lot of that, but it's all pretty tightly coupled to VS Code. You can build a more Web like experience, but frankly that doesn't look or feel quite write on desktop apps often times.

Personally I rather build a platform specific tool which works great on the specific platform and take advantage of the more powerful UI framework (WPF) and the core desktop features that every application needs.

For other things that aren't commercial tools that might be a total different story of course. For internal apps or other less high profile then Web UIs are probably perfectly adequate, but then of course you should ask whether you need a desktop app at all and just build a Web site.


Alberto Bar Noy
April 25, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

Hello Rick,

Great article! I do have a question however. On the "Was it all worth it part", why should one keep maintaining a WPF/WinForms app on .NET Core 3.x? Why not plan for a rewrite and package with electron like vscode was done? I mean what is the point apart from discarding full framework all together. This way one can enlarge one's audience and go beyond windows.


Rick Strahl
April 25, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

@Vatsan - thanks for the feedback.

As to DPI Awareness, I can't remember now but I'm doing some stuff internal with API calls to set the DPI awareness due to some dual monitor issues I was having related to the screen capture. As it is that never worked reliably (I can capture properly on the main screen, but on the second screen the window detection often times is off). I remember that the default settings in the manifest didn't work and the workaround did.


Rick Strahl
April 25, 2019

re: Faking out the .NET Runtime Version

@Eli - yes you'll always run on the latest version and in theory what you say is correct. However, there are a few things where the runtime itself compiles code differently depending on the version that's running it. For me it's these High DPI APIs where this happens and even if running on 4.6.2 (or later) with a compiled target of 4.5.2 just does not work because the compiled code just doesn't have that code path in it.

As I said this is a hack for a very specific scenario. At this point when I'm writing this I am requiring 4.6.2* because the version average for the user base has drastically changed. In fact, very soon I'll be moving it up to 4.7.2 as the user base is approaching 80% on that version.


Vatsan Madhavan
April 25, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

Hello Rick,

This is a great post - thanks for trying to use WPF on .NET Core 3.0. I love Markdown Monster, BTW!

One suggestion re your port at NET_Core_30_First_Shot/app.manifest, you'll likely have to set <dpiAware>true</dpiAware> or <dpiAwareness>system</dpiAwareness> (see doc) as a workaround for dotnet/wpf Issue #334.

Please continue filing issues on GitHub so that we'd know what to address.

If you get a test version of Markdown Monster working on .NET Core 3.0 (even with some functionality reduced), I'd love to give it a try!


MV10
April 25, 2019

re: First Steps in porting Markdown Monster WPF App to .NET Core 3.0

Somewhere in all the WPF issues on github, they're tracking performance as a future problem to tackle. Right now their focus is just making everything work right.

Regarding deployment size, keep in mind there is ongoing work to add tree-shaking (as well as single-file deployments). Although I'm not sure if that would conflict with your plugin approach. (Again, there is a discussion of that scenario somewhere out there on github.)


Gary Gary
April 24, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2

Ive struggled to find good ASP .NET Core hosting which is why I'm going to try and start my own! Im starting a managed hosting service. hosting.garygary.uk (the website is WIP)

  • IIS ASP (.NET Core) hosting with publishing through FTP or Web deploy from Β£5 per month
  • Small MSSQL Database hosting from Β£5 per month.
  • Cheaper than azure and direct customer support.

Andrew
April 24, 2019

re: Web Browser Control & Specifying the IE Version

Does this work when your program is MFC based and using the CHtmlView class?

Do you have to reboot after changing the keys?


Chris
April 23, 2019

re: Explicitly Ignoring Exceptions in C#

I think this is great. I appreciate your pragmatic approach to programming and I've always thought your code is approachable and easy to follow. Although I agree with the sentiment that most exceptions should be handled I recognize that cases do occur where someone may choose not to for valid reasons. I also think it's a neat and simple example of wrapping a lambda expression with logic you might want to execute around it.


George Gomez
April 22, 2019

re: Debouncing and Throttling Dispatcher Events

Rick,

Very nice debouncer and throttler. I was wondering if you think that we need to implement IDisposable. Will the DispatcherTimer leak memory? Thank you!

George


Rick Strahl
April 22, 2019

re: Adventures in .NET Core SDK Installation: Missing SDKs and 32 bit vs 64 bit

@JH - yeah that's an interesting point. I do run all my classic ASP.NET applications in 32 bit - less memory usage and last I tested better performance (although that's been a while). I suspect though that .NET Core is optimized better for 64 bit and going forward I think it'll be all 64 bit, so better to try go with that for the future IMHO.


JH
April 22, 2019

re: Adventures in .NET Core SDK Installation: Missing SDKs and 32 bit vs 64 bit

Thanks for the great write-up. As far as bitness and the IIS Server Hosting Pack, the guidance for preferring 32-bit applications and (application pools) is still unchanged after all these years. Time to revisit?

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2#supported-platforms

Supported platforms

Apps published for 32-bit (x86) and 64-bit (x64) deployment are supported. Deploy a 32-bit app unless the app:

  • Requires the larger virtual memory address space available to a 64-bit app.

  • Requires the larger IIS stack size.

  • Has 64-bit native dependencies.


Suyog Talekar
April 22, 2019

re: AngularJs ng-cloak Problems on large Pages

For me, overflow was creating problem, There was one extra overflow coming up while scrolling down page and DOM was not able to identify which scroll to use. I also changed from ng-show to ng-if to resolve this flickering issue


Lex Li
April 21, 2019

re: Adventures in .NET Core SDK Installation: Missing SDKs and 32 bit vs 64 bit

Thanks! I just realized that I hit the same issue, though my workaround was to always use "%ProgramFiles%\dotnet\dotnet.exe" instead of just dotnet in commands. Finally know the cause and now I can fix it.


Alex
April 20, 2019

re: Caveats with the runAllManagedModulesForAllRequests in IIS 7/8

In case anyone lands on this post in 2019 (after all it's the #1 result if you Google for "runAllManagedModulesForAllRequests") - afaik Visual Studio default project template does not include "ExtensionlessUrlHandler" these days, so touching runAllManagedModulesForAllRequests is not recommended these days, cause this will break your MVC projects.


Clarence Hwang
April 18, 2019

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

I refer to the article above on "Reading Request.Body for Raw Data... without parameters"

I'm using .NET Core 2.2 with attribute routing, i.e. at client side $.post(URL, Data) where URL is like https://domain.com/ctrl/id/name/contact (id/name/contact are parameters in attribute routing)

At the controller side, I'm using the codes suggested in your article above, i.e. read Request.Body as a stream and is always returning empty string.

After some trials and errors, I observed that without using attribute routing, i.e. URL becomes "https://domain.com/ctrl", the read from Request.Body works!

I tried Request.EnableBuffering() and rewinding Request.Body using Request.Body.Position=0 and it crashed without error, i.e. my VS just do nothing perpetually.

I'm new to Web Development, and wonder if it is conceptually sound to make attribute routing and Request.Body both work?


Jayson
April 16, 2019

re: Automating IIS Feature Installation with Powershell

I love powershell for installing almost everything now. This one works flawlessly for a standard Laserfiche Web deployment. Thanks so much!