@Matthew - I think this is new with ASP.NET Core 2.0 and the new default configuration defaults that it loads. In 2.0 they use common presets and adding configuration providers is one of the things that are set up by default. You can still do things manually if you prefer or remove providers during Configure() cycle.
@Santosh - that works for me. You may not be asked for permissions on a local domain - it may just automatically log you in.
I have a website which uses windows authentication and when i access it in IE browser it ask for user name and password in a prompt. But if i access the same url from Microsoft Web Browser active x control it is not asking for Username and password, it shows a blank page.
I have set Prompt Username and password option in Internet Explorer -> Internet Options.
I'm having a little trouble getting this to work on my project, I've tried everything but it seems like my Application_Error function isn't catching 404 errors. I never hit a breakpoint when I invoke a 404 via my localhost for example when I do: http://localhost:21118/asd , however if it ends with .aspx it does hit a breakpoint.
Any idea why this happens? Does it only handle requests that end with .aspx?
Good blog post - I bookmarked it and keep referring to it. The reason for the comment is I've been playing around with appsettings and trying various configurations for production. Anyhow, by chance I found out appsettings.json is automatically loaded, I'm not sure many people are aware of this. I was playing with an example similar to the one above here and added some settings in the json file and called them from an API expecting an error to be thrown and to my surprise they were read correctly. I then dug a bit deeper and found 5 configuration providers are automatically loaded (the following was in the VS Code terminal) ...
Providers [IEnumerable]:Count = 5
This is all a bit weird. I thought ASP.NET Core was only supposed to use what you specified ( unless these are what you might call 'sensible defaults').
September 15, 2017
"You can Inject the meta description on loading the website, previous to rendering. That what you don't need neither to modify the page (what usually is not up to you), neither to insert a registry key (that is a intrusive operation in the user machine)"
I'd love to see a working example of this, it makes the most sense to me?
p.s. great post thanks Rick 😃
Sure you can always build Web based APIs to interface between an old and new application. Run the old app on classic ASP.NET, run the new app on ASP.NET Core. It works, but hell that's going to be painful.
If you have to support FoxPro - use a platform that it works with, which is classic ASP.NET or something like Web Connection that's designed to work around the limitations of the STA threading model of FoxPro. But even that has limitations.
If you want to move forward into modern technologies, ditch the FoxPro code and re-write it. It'll only drag you down unless you continue running on tech that it's supported on.
Or is there any other workaround for this dilemma? such as writing a part of web application which is connected to foxpro business module with classic .NET and the new part with .NET Core and somehow connect these two parts together?
But a huge part of our current business module is written in Foxpro and in the first step, we also wanted to use this business module along with our new code which is totally written in .NET.
So we are trying to use our business module as COM objects and use them in ASP.NET Core.
So do you think there is any way to use COM objects in any language( other than .NET) is usable or will be usable(in the future that .NET Core is expanding) in .NET Core?
My situation is different from yours, but I think your method is what I need. Basically, I'm in school again, following a programming course. We're focusing on MVC and EF now, and make projects in class, that I put in Git or TFS and continue with at home.
In school I use their SQL DB, and at home, I have my own one. Up till now, I've just ignored the TFS/Git projects and recreated them to get some practice (changing the ConnectionString as needed), but if I'd just use the existing ones, could I use the method you describe here to recreate the DB at home?
To me it looks like it's exactly what I need; you're basically recreating a database with all models already created?
Someone has asked a question on how to inspect the actual SOAP messages; the thing is even if you enable logging from diagnostics (& set all attributes to true), in most cases you will not see the Security headers (when you are using client certificates).
A good alternative is the "Charles" tool ( https://www.charlesproxy.com/ ) - it is just brilliant / very easy to setup. You would have to select the client certificate within Charles and after that it simply acts as your proxy & will show you all outgoing & incoming messages.
PS: Thank you Rick for documenting this - as with several others, I have also spent a lot of hours on Stack overflow to get the hang of things. It'd have been great if I had found your article earlier. I found the "Charles" tool reference in one of StackOverflow articles & it has been a huge help - without being to see the actual messages, it is big black box & can be extremely frustrating.
@Steve No, it's definitely a problem with EF's DbContext. And it's just as bad in EF7 (Dotnet Core 1.1 version).
I'm implementing the DB for a new system. The DB is in its infancy. Just a dozen tables or so, our entire test dataset is 44MB. We were previously using one DbContext per operation and populating the DB with the test data took 1m 30s. When we tried to refactor from using raw FK relation to using EF navigation properties the fact that we were using separate DbContexts caused us to get duplicate key errors. So we refactored the operation to use a single DbContext.
Time to populate the test data went from 1m 30s to over 4h.
Now I'm scratching my head trying to work out what combination of disabling change tracking and bulk data operation will get this to work again. The thing is we need to use a single DbContext in a lot of cases to get correct transactioning. We also need to use a single DbContext for EF navigation properties to work smoothly without having to manually attach entities retrieved from one DbContext to another. But it doesn't seem to take much for using a single DbContext to bring the system to a grinding halt. Which means we are going to have to carefully examine and tune each operation on the basis of what kind of work it's doing.
It seems like we are still a long way from the ideal of projecting a a DB schema to an object graph and using it as if it was native data.
@Christoph - thanks for catching that. Updated.
@hassan - I haven't tried it but I would expect that to not work, since ASP.NET Core doesn't support STA apartment threading. Without that you can't call MTDLL components on multiple threads without corruption unless you schedule the components on your own.
Why do you want to do this anyway? It'd be better to just stick with classic ASP.NET for Windows specific and especially COM specific code.
+++ Rick ---
I believe there is a typo in the naming of the HTTP response header. Should X_UA_Compatible: IE=edge not read X-UA-Compatible: IE=edge?
See https://msdn.microsoft.com/en-us/library/ff955275(v=vs.85).aspx and https://en.wikipedia.org/wiki/List_of_HTTP_header_fields.
There are two occurrences of this misnamed HTTP response header in the blog.
Best regards, Christoph
It's 2017 and iOS 10.3 on iPad still have bugs in Safari rendering engine. Thank you very much to point me at the possible solution of my problem. More than a week I had a problem regarding -webkit-overflow-scrolling: touch; CSS style. I have a modal displayed with jQuery slideDown() function. Modal had position: fixed; style and when scrolling on iPad vertically or horizontally, first time when modal is displayed, everything is OK. But when I close modal with jQuery slideUp() function and then display it again, the modal content disappear when trying to scroll the content. I can't point at the web (it's corporate web based application). After many hour and many many attempts to fix the problem, suddenly I found your article! The fix was easy as... 😉 Replacing position: fixed; with position: absolute; simply fixed my problem. Work like a charm. Thank you many many times. God bless you.
I've created a DLL COM object in Foxpro and want to use it in ASP.NET Core, so far I've been unable to find a solution and
packaging it with Nuget didn't work either whereas I can use this same dll easily in standard ASP.NET.
Is there any way to use a Foxpro DLL COM object in ASP.NET Core? or Is there any difference between ASP.NET Core and ASP.NET in using
@Jonathan - You can subclass the service and then override each method and add the attributes there and just forward the calls to the base class. It's a bit of work but that would work. Then again you can easily run into trouble with that too as you have to make sure if the contract changes that you update attributes as well.
After a while searching i have found the solution based on your post. Thank you soo much.
I do have a question, would there be a better way to attach the behaviour in the code as opposed to the reference.cs as it would be lost if regenerated?
Thank you again, you have saved me soo much time trying to figure out what was in fact going on with the messages!
I just checked at relevant locations but I did not find any registry that was already set. Also, I don't feel that the Edge tag is overriding these registries as I know of few other applications which authenticate the exact same way. But these are independent applications and not powershell snapins.
Strangely, the ApiExceptionFilter doesnt modify my context.
I updated correctly my startup.cs with :
In my controller i have:
throw new ApiException("Test");
But in my ErrorInfo.ts, there is no error message ...
Do you have an idea?
@Vikas - Check to see whether the version is set on HKLM or HKCU already. Might be something is overriding the value you are setting.
This should work, but note that the meta Edge tag will override the underlying Reg setting, so if the page has that header in there and it's pegged to a specific IE version that might be the problem. MS internal pages often use this to ensure backwards compatibility.
@Rick, thanks for your response.
I am loading a snapin in Powershell and to use it I need to authenticate. It is this authentication dialog where the latest IE version has to be used. I open task manager and right click on "Authentication" and choose "Go to process" it always shows me powershell.exe. That is why I was creating those registries w.r.t powershell.exe
@Vikas - Powershell.exe is probably not your host process. Powershell is console - it doesn't have direct access to the Windowing subsystem so if you have UI of some sort there must be something else running that.
Did not work for me. I have to specify these registry for powershell.exe as my snapin works with Powershell. Do we have to do something different for Powershell snapins?
I've had the same trouble in the past trying to debug embedded script in a .NET application. You can actually make it even easier to debug embedded script by creating a C++ "Empty Project" in Visual Studio. You can then have the project set to run an external application, like the build output from another project in your solution, and set the C++ project to debug Script directly. Finally, set the C++ project as your Startup project.
It takes a couple minutes to set up, but at the end, you can just F5 your solution, set a breakpoint in your script, and watch it break right where you want it to. Of course, the downside to this approach is that you have to have the Visual C++ components installed.
I wish we had the class libraries automatically analysed for the lowest needed dependencies either during packaging or at least as a separate command for the class library project.
"So rather than referencing the entire framework, it's much better to reference just the individual components your application actually needs"
I don't think this is a good idea, it may cause reference conflict for the consumer of your library.
Hilarious! and this one too:
"File this one into the Mr. Murpy Loves Me"
I would subtle this, "Don't be npm." 😃 If only David's advice was heard there.
The only reason people are still using CHM files is because Microsoft hasn't provided anything new that is supported by Windows. Even the MFC Wizards no longer have a checkbox to generate support for help. It seems Microsoft has decided that online help no longer matters. Yes, I realize I can use Web pages. But it's fairly complex to have fully context-sensitive help using Web pages. And context-sensitive help seems to be another thing Microsoft has decided is not really important, even for some of their own products.
Good job, nice article. When I saw Microsoft.AspNetCore.All at some talks, I don't like this meta-package, not only because it loads eeeeverything, but 'cause we will see some developers to use it, neglecting and ignoring the things described in the post.
@BB - I think the process is the same for portable libraries. You just need to find the target framework moniker for this. https://docs.microsoft.com/en-us/nuget/schema/target-frameworks (ie. portable-net40+win8+sl4+wp7)
@Lex - it works for me in Visual Studio 2017.3.5. VS happily works with it, but you can't change the TFM in the dialogs. You have to modify the .csproj directly. But it works fine. VS is just using the command line tools to build after all so no reason why this shouldn't work.
@Richard - LOL - you're so right! Fixed...
How can you multi target .net standard and portable class library profile44(xamarin forms)?
Great article. Our shop is slowly making the jump to netstandard and there have been a few bumps along the way. I appreciate the hint on the documentation. I met you at PADNUG a few months back, I'll say, "Hi!" at DevIntersection.
Visual Studio does not like the conditions, so though the trick works fine for command line, it breaks VS experience.
I blogged about that (and more) in my blog post, https://blog.lextudio.com/tips-for-net-nuget-package-authors-august-2017-48f07604e4a0
The workaround I use is to "sed" away the net*** TFM on non-Windows platforms in a shell script.
"The slowdown was caused by the errand dictionaries."
"I also have no idea where these errand spell check dictionaries came from."
"The slowdown was caused by the errand dictionaries."
"I also have no idea where these errand spell check dictionaries came from."
A perfect example of why checking the spelling sometimes just isn't enough! 😃
I assume you meant "errant".
@Rick Wanted to point out that the sub-app works fine unless I add a php handler to the main site's config file to handle php requests.
Aso soon as I add below, the sub-app cannot find the static contents.
<add name="PHP54_via_FastCGI" path="*.php" verb="GET,HEAD,POST" type="" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.4\php-cgi.exe" resourceType="Either" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="aspNetCore" path="*" verb="*" type="" modules="AspNetCoreModule" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
Effectively I thought it would end up being handled by kestrel but somehow, it doesn't work...
I guess it is actually handled by one of the handlers but not correctly, hence never really passing the request to Kestrel... I will have to investigate it 😃
@Rick - I did the same. Created a new application inside the site and assigned it a separate application pool and also removed the handler. The application loads but it cannot find any of the static files.
I agree with @Edward saying .Net Core has been a complete mess. Why can't MS just take their time to build one platform that is just stable and hide all these implementation details? Why should I care about BCL, FCL and a whole bunch of other concepts when all I want is run an app? I don't have to learn any of that when running Java...
Is there any way I share the session between an ASP.Net application (Running on .Net 4.5 framework) and ASP.Net Core (Running on Core 2) application. Where ASP.Net Core Website is created under ASP.Net website as a Application.
Thanks in Advance.
Is there any plan to make a .NET standard cross platform version of the West Wind WebSurge tool? It would be awesome to be able to use it on Mac and Linux.
@Os1r1s110 - You probably need to explicitly add a static file handler for .map files as well.However, if you don't then those requests should still end up in Kestrel for processing so they should work - it just won't take advantage of IIS caching and auto-compression.
Great article Rick, thanks for sharing.
I would have a little question about the static file setup though, I used your code above but it seems to cause problems when trying to reach a sourcemap file.
For example, I have my compiled assets under wwwroot/css/ or wwwroot/js/ and they are discovered without problem by IIS but as soon as I'm under dev. environment and try to load sourcemaps, it breaks somewhere and google or any other browser cannot access the files, would you have an idea of how to fix this?
I tried changing the regex for the url rewrite but it doesn't work...
Thanks in advance and again, great post!
I could not get this to work via command line arguments, it always showed in the console as listening on localhost.
I noticed while debugging what exactly ended up in my configuration bag when I discovered this
I just set this environment variable in my project config Debug tab and it all works.
I have spent a good 10 hours on finding the solution to this. My google history of search terms apply is crazy. I'm using MVC in conjunction with Kendo controls so I've spent my time looking at Kendo's Window as the primary cause. ModelState. How simple.
In my case I'm validating addresses, and if the address matches (but a different case) I wanted to replace it with the proper validate UPS address. I was able to see it in all of the data, it just wanted reflecting in the controls. With just a few lines of code I'm able to reset the 6 controls that I care about.