Recent Comments



EZE
Today

re: Azure VM Blues: Fighting a losing Performance Battle

We're trying to run a VEEAM server in Azure as a target. We wanted our backups in Azure so that we could restore them in a DR scenario, or maybe restore for DEV testing. However, even the VEEAM server is horribly slow (A3 standard). Same type of delays as described. Veeam uses local Disk for a simple SQL install, and WAN Accelerator cache. Striped 4TB of disk for backups themselves, but simple file transfers within the VM are lucky to get over 10MB/s. GUI slowness is blatantly apparent. I too thought about doing an affinity group, but Microsoft is strongly recommending against them now, and not giving the ability to create them in the new portal. I really wanted Azure to be part of our future infrastructure (VM's, services, Hyper-v Replica), but I am incredibly disappointed. Having to rethink our entire DR and infrastructure strategy...

Rick Strahl
Yesterday

re: Rebooting Database Localization for ASP.NET with West Wind Globalization 2.0

@Amine - good suggestions. I have to take a look and see how feasible it is to have all resources in the list. We do need to know what the active resourceset is in order to perform some perfunctionary operations.

Could you create an Issue on Github so this can be tracked? https://github.com/RickStrahl/Westwind.Globalization/issues

twomm
Wednesday

re: Auto Selecting Cultures for Localization in ASP.NET

Yes, I will try the outlined approach and if I see any issues, I will use a module.
Thanks for your answer.

Rick Strahl
Wednesday

re: Auto Selecting Cultures for Localization in ASP.NET

@twomm - I think you should be fine because anything you do in the GetHandler happens before the MVC routehandler gets control of the request. I think you do want to try and set the culture/uiCulture as soon as possible in order to make sure that all aspects of the request like authentication get to use the current culture settings. THat's generally why you want to do things in the BeginRequest() cycle if possible.

But if you're changing culture based on the route you have no choice to do it until later, unless you create a module that looks at the URL and figures out the route culture earlier in the cycle (which wouldn't be difficult to do since you know what the culture Urls look like).

Bassem Mohsen
Wednesday

re: HttpWebRequest and Ignoring SSL Certificate Errors

To elaborate on Michael Bray's comment, here is how you skip the certificate validation for a particular request without affecting the rest of the application.

httpWebRequest.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

This code requires .NET 4.5 or a later version.

Shawn
Wednesday

re: Using FontAwesome Fonts for HTML Radio Buttons and Checkboxes

I'm having the same issue as those above with chrome and firefox. I'm toying with it now, but please let me know of any suggestions. So far, no luck with the IDs.

twomm
Wednesday

re: Auto Selecting Cultures for Localization in ASP.NET

Hi Rick,

nice post, as usual!

I am wondering if you could give some input on the following. It is a bit more about routing, but related to the topic:
I am using MVC and have to support URLs, that contain the culture and the same URLs, that do not.
So basically, I have one route with "culture" in the URL and a matching route without culture in the URL, where I set the culture to a defaults "notset".

            routes.MapRoute(
                name: "Default",
                url: "{culture}/{controller}/{action}/{id}",
                defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional },
                constraints: new { culture = new CultureConstraint(Culture.enUS, ...) },
                namespaces: new[] { "..." })
                .RouteHandler = new CultureRouteHandler();
            routes.MapRoute(
                name: "DefaultCulture",
                url: "{controller}/{action}/{id}",
                defaults: new { culture = "notset", controller = "Default", action = "Index", id = UrlParameter.Optional },
                constraints: new { culture = "notset" },
                namespaces: new[] { "..." })
                .RouteHandler = new CultureRouteHandler();


On all my routes, I use a custom CultureRouteHandler. Within that in GetHttpHandler, if the culture is set to "notset", I try to get it from the accept-header, or use a system default one. In the end I overwrite
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            ...
            // read culture if it is set to "notset" from routing
            ...
            requestContext.RouteData.Values["culture"] = culture;
            ...
            // set on CurrentThread
            ...
         }

with the desired culture.

Now my question is, can this have any implications on the further request pipeline, or is that approach fine?

Any thoughts would be much appreciated!

Thanks

Amine
June 27, 2015

re: Rebooting Database Localization for ASP.NET with West Wind Globalization 2.0

Hi Rick. and Thanks for remarkable effort.

I want to suggest two improvements regarding to the Web AdminLocalization Interface.

- The Selector of resourceSet on bottom is not so intuitive. I believe making it on the left side and presenting Keys/resourceSets in hierarchical view will be better.
- The search only within the Current resourceSet, I beleive It is not best. because in real wold Projects we have to deal with multiple resourceSet, and not have to know each resource within which resourceSet before searching so searching on Whole will be great. And will be more cool if you offer search within content of strings not only the keys.

Amine
June 27, 2015

re: ASP.NET MVC, Localization and Westwind.Globalization for Db Resources

Hello
and Thanks for post,
I am wondering if :
- multiple selection-deletion of resource elements is offered on Backend WebApp
- if the backup, import-restore is available as option because in many cases, we have the machines of developers that need to import resources filled by Virtual Assistants and persons that have more time for localization/globalization stuff. I know that with Sql scripts we can do it, but mainly in managing duplicate entries, will be a pain between more than 2 machines.

Rooc
June 25, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Louis: in the sample app it is used in a console app without the dependency injection:
https://github.com/aspnet/Logging/blob/dev/samples/SampleApp/Program.cs

will this work for you?

Rooc
June 25, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Hi Rick,

Do you have any idea how you do the following on linux
SET DATA:APPSETTINGS:THEMEOPTIONS:THEMENAME=Console

I can't seem to find how to excape the colon in the key name, so it says it's not a valid identifier... :S

Rick Strahl
June 24, 2015

re: Rebooting Database Localization for ASP.NET with West Wind Globalization 2.0

@Tyler - thanks for the heads up. Yup it was late last night when I finally got this done!

Rick Strahl
June 24, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

You can only use this new mechanism in a DNX application. While you can build a Console app it'll have the dependency injection system so you should be able to access the objects from there. I'm not sure what the syntax would be to use any of this without DI - unfortunately it's not meant to be used that way (as are most other pieces in the DNX framework which I think is pretty annoying - DI has its place, but it shouldn't always be used in every situation).

Louis S. Berman
June 24, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Hi! How would one go about using strongly typed configuration in a standard console app WITHOUT dependency injection? I want to load and use the configuration in Program.Main...

Neil
June 24, 2015

re: A jquery-watch Plug-in for watching CSS styles and Attributes

Your plugin is great but I find it has one flaw when i use it. The first time thru it does not pickup the change. After that it works great. Any thoughts. I am using it in a jsp if that has any bearing on the answer.

Thanks Again.

Tyler Jensen
June 24, 2015

re: Rebooting Database Localization for ASP.NET with West Wind Globalization 2.0

Hi Rick. Thanks for the great work. Quick note. I think you may have a copy/paste bug in the blog text with respect to package names.

david
June 24, 2015

re: Rebooting Database Localization for ASP.NET with West Wind Globalization 2.0

Innovated ideas turned into a functional application. Localization is the future.

Adrian
June 23, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Rick, not using IIS but using the desktop clr, I suppose that changes in desing must be made.

Rick Strahl
June 23, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Adrian - Are you running under IIS or self host? Self-host will most definitely not work since you won't have access to the IIS infrastructure that sets up the web config system and there is no HttpContext.

Using IIS you'll get the infrastructure, but I'm not 100% if you can get access to HttpContext from within a DNX application - have to try that to see. Ultimately, that's how the web configuration finds all the paths and locations for configuration.

Adrian
June 23, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Rick, I'm afraid that is not the case, because when I make a test, it doesn't find the web.config in the wwwroot directory, it does if it is loaded in IIS, when I print the path of where is looking for the web.config file it gives me this:

C:\Users\inspiron\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta6-12108\bin\dnx.exe.config

It is the path of dnx, and it makes sense, because I'm executing the application with dnx.

So, the best I can do is look for the file in the current directory, a fragile solution.

Rick Strahl
June 23, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Adrian - Assemblies that are using app.config/web.config currently are going to be full framework assemblies and they will still be able to add a CLR reference to System.Configuration. Everything can continue to work the same as before for those assemblies as long as the config files are present.

CoreCLR doesn't have a built in mechanism for reading this data, so you'd have to build your own if you need it, but then you wouldn't do that. CoreCLR will just use the new configuration system.

Rick Strahl
June 23, 2015

re: Using .NET HttpClient to capture partial Responses

@Stevec - unfortunately non the wiser. In my particular application I just use HttpWebRequest and set the buffer size as small as possible. If you really want something small the only way to do it is with raw sockets and even then you get a fair bit of buffering. And personally I don't want to rewrite all HTTP logic for generic requests. If you're dealing with simple scenarios of known requests then sockets is probably the best choice.

Adrián
June 23, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

And how will assemblies that are currently using App.config or web.config to get some values Access to this config.json file?

It is only accesible via ASP.NET 5?

steveC
June 23, 2015

re: Using .NET HttpClient to capture partial Responses

A year later, what's the final word on this issue?

Thanks.

Rooc
June 20, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Ok, davidfowler responded (https://github.com/aspnet/Configuration/pull/205) and you need to inject the IApplicationEnvironment into the constructor to get the correct path for the ConfigurationBuilder constructor

//add IApplicationEnvironment to contructor and use appEnv.ApplicationBasePath 
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.
            var configuration = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                 .AddJsonFile("config.json")
                 .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true)
             .AddEnvironmentVariables();
 
            Configuration = configuration.Build();
        }

Rick Strahl
June 20, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Philip

1. You can create multiple classes, both of different types as well as of the same type by providing different names.

2. The configuration objects are loaded once at startup and then not touched again. But they are just plain POCO objects with writable properties so you can definitely change the values and those changed values will reflect in subsequent accesses. So no not immutable, but loaded from store only once. Haven't checked to see if there might be a way to reload from store which would be useful.

3. This could be supported and JSON.NET does support comments AFAIK, but I think JSON.NET is not loaded on initial startup and there's some custom parser doing the JSON reading. That may have changed, but I agree. Comments are a vital feature and the complaints have been lound on that.

Rick Strahl
June 20, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

reposted from another thread from Philip Daniels:

A few points

1. Can I "multi-instance" the settings? As an example, if I have a PostcodeConfiguration class, can I create 3 different configurations, one to hold Scottish postcodes, one to hold GreaterLondonPostcodes, and one to hold BlacklistedPostcodes? Same class, different data. It is easy to do this in the existing configuration system using named sections.

2. Are the injected settings immutable? They don't look like it based on the example. They really ought to be, classes that need access to the settings rarely, if ever, actually need to change them. I can't recall ever having to change a setting in code. And immutability allows you to create them as singletons.

3. OK, the existing XML based config system may be verbose but at least it allows comments, which can be a great help to support people. JSON, for reasons mainly related to obstinancy, does not allow comments.

Like you I have written my own little utility to deal with the configuration system (BassUtils on NuGet). The approach I took was to define a class - just like your LoggingConfiguration, for example, then define a read-only interface for that class (ILoggingConfiguration). Services that need access to the settings just declare a dependency on the interface and IoC supplies the relevant instance. And the loading of the LoggingConfiguration class from the XML was done using the XmlSerializer, and can deal with things like defaults, and validation annotations such as regexes, min/max ranges etc.

Rick Strahl
June 20, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Ryan - unfortunately not. I thought that that would work, but they are not parsing the value but using Convert behind the scenes and that doesn't translate enums. This is fixed in post beta 4 and in my follow up post http://weblog.west-wind.com/posts/2015/Jun/09/Using-and-Debugging-External-Source-Code-Packages-in-ASPNET-5 I describe exactly what the problem is and how to work around it.

Rooc
June 20, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Just a headsup for anyone trying this on the "dev" branch the Configuration.GetSubKey has been renamed to Configuration.GetConfigurationSection. And in the startup you need to AddJsonFile on the IConfigurationBinder instead of the IConfiguraiont
so:
            //Not sure which path to specify, this is the "wwwroot" path which is wrong for the config file
            var configuration = new ConfigurationBuilder(env.WebRootPath)
                //You could specify "..//config.json" but that will not work in published site
                 .AddJsonFile("config.json")
                 .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true)
             .AddEnvironmentVariables();
 
            Configuration = configuration.Build();

And
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));

Ryan Tuck
June 18, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Wouldn't the Enum be serialized off the underlying Int type, not the string? Thought that this would work similarly to Controller Parameter binding on Enums...? They can take text values and parse, or Int values can't they?

Cheers,
Ryan

Nikola
June 18, 2015

re: Creating a dynamic, extensible C# Expando Object

Hi, i've tried out your expando object and it hold nicely, however it's not quite what i'm looking for. I need to be able to see when properties are changed so it can be usable with WPF. Is that even possible?

ITLackey
June 17, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Has anyone found a way to persist changes to the config values? I have tried using the IConfiguration.Set(string, string) method but this appears to only be an in memory copy. Once the site is restarted the old values are reloaded. No changes are made to the .config files. I realize that I could write could outside of the API to manage this by writing out to the JSON file etc. Just want to make sure I am not missing "the right way" to do this to account for the different config sources etc.

Thanks!

Imranhere2
June 14, 2015

re: Azure VM Blues: Fighting a losing Performance Battle

Depressing! What's wrong - Hyper-V or just lots of Hype and bugger all behind it? For SQL I/O is king and its hard to believe they cannot get it right!

Elmar
June 12, 2015

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

Flip, just ran into the same behavior which took me by surprise.
Applied the
ModelState.Remove("key")
option which successfully solved the problem.
thx

Rick Strahl
June 11, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Kyle - I don't think you can do that. As far as I can see the IApplicationBuilder you'd need to resolve the reference to the configuration is not available until after ConfigureServices() completes. This means you have to stick to this syntax instead:

services.ConfigureCookieAuthentication(options =>
    {
        options.CookieName = Configuration["appSettings:CookieName"];
    });


or maybe more appropriately, defer the logic to do any actual configuration in the Configure() method which can simply inject the value:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
                              ILoggerFactory loggerfactory,
                              IOptions<AppSettings> appSettings)
{
       var name = appSettings.Options.CookieName;
}

Ben T
June 11, 2015

re: Hosting SignalR under SSL/https

Thanks to Richard L! I hit the "The Parameter is Incorrect" problem. It would have taken ages to figure out that hidden character issue.

Kyle
June 11, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Is it possible to access the strongly typed AppSettings class from inside the Startup.cs ConfigureServices method (after the services.Configure mapping)? I need access to some of those properties for additional service configuration. For example:

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<AppSettings>(Configuration.GetSubKey("appSettings"));
 
    // I now want to access the mapped app settings for other service configuration, example:
 
    services.ConfigureCookieAuthentication(options =>
    {
        options.CookieName = appSettings.Options.CookieName;
    });
}


Can I resolve the AppSettings class in some way immediately after this initial services.Configure?

Thanks.

Rick Strahl
June 10, 2015

re: Blocking IIS IP Addresses with ASP.NET

@Todd, there's no 'tool'. The code for this is in the post above so you can add this yourself to a page. Alternately if you need help I can probably help you get this set up, but should be pretty straight forward. The APIs changed in IIS7 and later, but the same principles can still be applied.

Todd
June 10, 2015

re: Blocking IIS IP Addresses with ASP.NET

Hi Rick - is the West Wind component for blocking IIS IP Address with ASP.NET still available? We have a couple of old W2K3 servers that house some newer projects, and we notice that the Russians have been picking at it. We would like to block the entire range from the Russian Federation, and probably some others like China, etc. I ran across your project, but I don't know which component from WestWind to use? Thanks!

Todd

Harry McIntyre
June 10, 2015

re: How to manage Content in NuGet Packages?

I've got a project (FormFactory) which has customizable js/css/cshtml templates. What I did was to mark the files as EmbeddedResources and include in the core library dll. I have a second {projectname}.Templates package which can be optionally installed. If the user just wants to avoid clutter then they can use my EmbeddedResourceVirtualPathProvider package. This will load files from the assembly, unless the file is present on disk i.e. they have installed the Templates package;

Ron Birk
June 09, 2015

re: Back to Basics: UTC and TimeZones in .NET Web Apps

Using "var dt = new Date().toString();" doesn't seem to work on Chinese browsers (for example) and also not on IE9. As the time zone will either be localized or not shown at all depending on language and browser version.

Rick Strahl
June 06, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Peter - yup I agree to some extent that it's easy enough to create strongly typed classes and expost them as static properties/values. However, you are tying yourself very tightly to the AppSettings class which doesn't work very well if you need multiple config stores. That's where the new tooling provides many improvements by providing other configuration sources (.json, .ini, EnvironmentVars, UserSecrets by default) as well as the ability to extend.

As as I mentioned in the post I have a configuration library that provides similar functionality in current versions of .NET, which fits somewhere in the middle between what you're doing with your static class and what vNext provides. The advantage of a library is that you get to abstract away the provider so that you can store in different configuration stores, which makes it much easier to re-use the functionality in components which is difficult and ugly for your implementation (but then again it may not be needed).

You might want to check out West Wind ApplicationConfiguration which lets you use simple strongly typed classes that handle all the strong type conversions for you and access them easily from anywhere in your app via a staticly stored instance:
https://github.com/RickStrahl/Westwind.ApplicationConfiguration

Peter Lanoie
June 06, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

It's interesting to see this transition. I've never considered using AppSettings to be a source of terrible difficultly. However, I completely agree with the approach of making it strongly typed. In fact, for many years I have used a static config class to make all my AppSetting values accessed as strongly typed values and easily discoverable while coding. Using your nested type example above, this is what I'd have:

namespace MyWebSite.Configuration
{
    public static class Config
    {
        public static string SiteTitle { get { return ConfigurationManager.AppSettings["SiteTitle"]; } }
        public static int MaxListCount { get { return int.Parse(ConfigurationManager.AppSettings["MaxListCount"] ?? "15"); } }
        public static class ThemeOptions {
            public static string ThemeName { get { return ConfigurationManager.AppSettings["Theme:Name"]; } }
            public static string Font { get { return ConfigurationManager.AppSettings["Theme:Font"]; } }
        }
    }
}

Then it's just a matter of accessing the config values via the static class properties, from any code, without the complexity of DI, and the standard web.config override functions apply to it:
   <title>@Configuration.Config.SiteTitle</title>
 
   Configuration.Config.ThemeOptions.Font

strandedpirate
June 05, 2015

re: Azure VM Blues: Fighting a losing Performance Battle

Thanks for this info. We started with an Azure S2 Standard Website to host just a few web applications and the performance is horrible. Averages 2+ second page load times despite implementing every conceivable caching scheme and transport size reduction imaginable and we have next to no traffic. I couldn't imagine how bad it would be if we actually took off one day and got some real traffic. We considered going for a VM to see if performance would improve but given your experience it looks to be pointless.

It really comes down to one thing, because I've lived it first hand, some no name director at MS who's mantra is lowering CAPEX and increasing profits. The end result is every machine is over provisioned and everyone pays the price, literally. This happened internally at a previous employer, DELL. They wanted to reduce CAPEX and moved to virtualize every machine possible and then over provisioned everything. Literally 25-35 VM's running on machines that could at most handle 16. Net result is waiting 5+ minutes from login screen to the desktop. An hour+ to install .Net 3.5 and on and on... When your OPEX is fixed, because they are salary, then who cares right? Wrong, burn out/turn over bonanza. Took two years and 400+ engineers screaming to fix the "policy".

But this is MS and its "for profit" so it won't get fixed and they want it that way. Time for everyone to "scale" as MS calls it (ahem, pay twice as much) or elucidate one's self and find another host. We'll probably purchase a machine and co-locate it a local data-center in the near future. Azure is ridiculous. All the bells and whistles moving at a snail's pace.. no thanks.

P.S> you can't even attach a performance tuner to an Azure database. They want you in the dark, because without knowledge you can't make an informed choice and let rumors and confusion muddy the way forward.

Rick Strahl
June 04, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

@Lex, yes web.config is still used *if you are running on IIS*, since it controls IIS's configuration. There are also some config settings that are required to get ASP.NET 5 bootstrapped in IIS currently. But - the web.config is not used if you self-host, running httplistener or kestrel, nor is it used by the application when you're running under IIS. In short, web.config is no longer considered a feature that will 'be there' for different implementations.

@Ryan - the default implementation looks in a specific folder as part of the Web application. I don't see any overrides for locating the file elsewhere. However, you can create custom providers that can do this. You could sublcass the provider and add path info and management into the implementation then use that implementation.

@Ken - You shouldn't need transforms with the ability to load special 'Environment' versions of configuration files that override the 'base' functionality. You would just ship a custom config file for each environment (config.Production.json, config.Staging.config, config.Development.json) and put your overrides in each as needed.

Ken Burkhardt
June 04, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Thanks for the article. Just curious: What's the best practice for the old web.config transforms? (a la dev, qa, production, etc)

support
June 03, 2015

re: An Introduction to ASP.NET Web API

I know I came across this article pretty late, but just wanted to express my thanks for taking the time to explain the web api process. A good starting point for anyone looking . The only thing is I'd make it printer friendly as this is the kind of reference material you'd want to have nearby on your desk :)

Ryan Heath
June 03, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

Is it possible to load a json config file that is not located in the app root but somewhere else, say, c:\configs\... ?

Thanks

// Ryan

Lex Li
June 03, 2015

re: Strongly typed AppSettings Configuration in ASP.NET 5

But web.config is still used by IIS 7-10 as they need to store settings in <system.webServer>. By supporting the JSON based new configuration system, ASP.NET also loses the capability to validate the data based on my current understanding. Correct me if I am wrong. Thanks for this great post.

Bart Verkoeijen
June 02, 2015

re: IIS SSL Certificate Renewal Pain

Thanks a ton, Rick! The private key wouldn't show up after importing the CA response. I think it was because I created two CSRs for the same friendly name. This was necessary because we requested two different certificate types (regular and extended validation). The restore command worked perfectly.