In this section, I thought to introduce my another book on ASP.NET Identity. This is extremely important topic, which developer often skips. This book not only gives complete overview of how to get started with Identity, rather here you will learn bits and pieces about Identity in detail. Most important thing with Identity is customization and understanding usage of the same.
In this section, we will continue from the last section where in I have discussed some of the tools which you should be knowing to make your life easy going while doing development. Here, I have presented few more links to the useful tools.
Hi Friends, In this section, I am going to talk about the tools which I am using on regular basis to really make the app fast, robust, fluid and also which makes developer life easy going by making them more efficient while coding.
In today’s discussion, we’ll delve further to some more interesting features on ASP.NET 5. So, lets begin the show. Now, Let’s talk about the different CLR Types available with this project. So, when i talk about different CLRs; There are actually 2 versions of CLRs. 1st one is the usual one which has the full blown version of CLR which we have been using since it’s inception. Another one is the minimized version or also known as cloud optimized version of CLR. Now, let’s go ahead and check project settings.
As you can see in the above screen shot; my default setting is against full blown CLR which is running on the X86 machine. Now, if you see the drop down shown below. you will notice that i also have the option for cloud optimized version.
Now, let’s change the environment to cloud version and then run the app and inspect the output of the greet controller which we created in previous section. It should print my name there.
Now, let’s go ahead and debug this controller. So, now when i refresh the page it will hit the breakpoint as shown below.
Here, when I go in the modules section as shown below in the screen shot. It will list the complete flow. So, here you can see from where all the binaries loading. Basically modules are nothing but have one to one mapping with assemblies.But, you can also have multiple module per assembly. Now, this module window is showing me what all modules are loaded in the application.
Now, one point to note here that all these modules are coming from one location that is from user’s location as highlighted above. Let’s jump to this location for a minute and inspect the same.
Now, when I go inside there; i can see that there is nuget package file or NUPKG file which is around 14 MB.
This is complete Core CLR. Can you imagine. Now, what i can do is i can simply take this file and copy to different system my .NET Core version is ready. This bin directory here is the extracted version of this nuget package as shown in the below screen shot.
Also, when you go to the runtime folder and go to full blown CLR folder as shown below.
You will notice that size of the NUPKG file is very less compared to Core CLR version. Confused?
In case of full blown CLR, all components get loaded from GAC (Global Assembly Cache) not from here. But, it doesn’t mean that there is no centralized repository for Core CLR. So, if you go to below location; you will find packages folder.
So, now this will be the centralized repository for your Core CLR.
So, whenever, we install any dependencies it will sit here in this packages folder. So, ASP.NET 5 completely embraces nuget package. We manage dependencies via nuget package. We can have CLR stored through nuget package. Hence, these packages folder are referred as Global Package Cache.
Now, project.json is not only used to have the nuget dependencies only. we can have different project dependencies also listed here within the same solution. For example, let’s go ahead and add class library project to the solution folder. Make sure you install Vnext version of class library which means this class library project can have all the flexibilities of dynamic compilation what we have been using so far.
Once you added the project. Your solution will look like shown below. So, even the new project gets added under the src folder.
You will also notice that this new class library project also added new project.json file which also lists the dependencies accordingly for running Class library project.
Now, if i have to use this project in my web project; then i just need to include this newly created project in the dependencies section of project.json file of web project as shown below.
Now, when you don’t provide the version name against the package or project it will pull the latest one. Let’s go ahead and create some method in the class library project to return some meaningful thing.
Let’s use the same in Greet controller.
With this i will wrap this session. In the next section we’ll delve further into new features of ASP.NET 5. Till then stay tuned and Happy Coding.
In this section, we’ll delve further in the new ASP.NET 5 project. When you take a closer look at the ASP.NET 5 project, you will see that there are many things which are carry forwarded like Model, View, Controller, clean separation of concerns and may more. But, there are also some significant changes around ASP.NET 5. Now, the root of the website is no longer the root of the project. By default, root will be WWWroot folder. The idea behind this to maintain the clean separation between the files at the web-server retrieved and sent to the client and the files which contains the logic and configuration. Static files like JS, CSS, HTMLs can live in WWWroot folder.
Now, lets suppose when i run the app and tried to see the image which i have placed in My Imgaes folder, then it will give me 404 error.
On the other hand, if i go ahead and add the same folder in WWWroot folder and try to navigate the same then it will produce me the result.
so, the point is all static files are served by root folder and logical stuffs served by project space as we initially saw, when i added controller in the controller’s folder and it took effect. One more thing you might have observed that there is no web.config file now in the solution. Also now there is no Global.asax file; however the same is replaced by startup.cs file. But, we’ll see this later. 1st let’s see project.json file. This file now manages many aspects of website.
First thing which you will notice here that root folder is set to WWWroot here. So, this is the place which is telling website that this is the root folder. So begin the show from here. This you can change as well or rename if you like to. Now, this configuration file is in JSON format. This is also telling the ASP.NET runtime what dependencies project is going to need. In this new ASP.NET 5 system there is a new way to manage dependencies. No need to reference assemblies and store the lists of referenced assemblies in the project file. Instead we refer to nuget packages as dependencies and these dependencies are listed in our project.json file. Now, there are couple of reasons for this change. One reason is to simplify the dependency management. Another good reason for this is that ASP.NET is moving away from VS dependency. So, in future i can use any text editor to build the ASP.NET App.
Now, these dependencies can be both the ways. One way which we used already shown below in the screen shot.
Now, the UI of this also changed. Initially we used to have Modal window. Now, this is more like complete screen giving wider visibility. I can also see the installed templates like
Also, i still have the flexibility of different nuget source.
2nd Option is via project.json file. Let’s suppose i am planning to install some custom package. Then i can do like shown below as well
However, whatever package you install; you can find its references under “References“. Below, in the screen shot you can see that there are two versions of runtime here. 1st one is the core version and 2nd one is the cloud optimized version.
Now, let’s collapse the same and drill into it.
Now, here dependency management system will keep your assemblies in nice tree structure. So, it nicely tells which package are dependent on which package.
Now, as far as Framework and runtime is concerned as you can see below in the screen shot; i have both frameworks listed here.
So, whenever i am building the solution i am building against both of these frameworks. By building against both i am actually ensuring that it will work well against both the frameworks. This also means whenever i am switching platform my code won’t break there.
But, let’s go ahead and break something here. You remember in the last segment i created one new controller with a notepad. Now, let’s modify the same and refresh the app.
so, as you can see that it says that GetCallingAssembly() which is part of System.Reflection is not supported in the cloud optimized version. But, let’s suppose i overlooked this error and refresh the app.So, it actually produced me desired result.
But, when i explicitly build the project and checked the output window, then it gave me below error message.
so, building with error but application is working fine with full blown CLR. Now, if you have decided that you don’t want CORE CLR version. so, you can just comment the Core CLR section in the project.json file as shown below in the screen shot.
Now, as soon as i commented the above section, below references got refreshed automatically.
Now, when i build the app then it will build fine.
But, suppose you want the other way means you would like to keep the cloud optimized version also and build should also succeed. For this scenario i need to refer the conditional build as shown below.
With this i would like to wrap this 2nd session ASP.NET 5 New Features. We will delve further in the coming series. Till then stay tuned ad Happy Coding.
In this section, we’ll see that major changes on ASP.NET 5. The very 1st change is on the lines of Project system. Projects are now based on File System. So, all you need to do is add something to a project say new source code file is just to place the file in the right directory. So, you can edit the source code file, save the file and build just happens dynamically. Thanks to new Roslyn compiler which compiles the source code in memory which allows for faster build and faster refresh.
The project structure itself changed from previous versions. Also one point to note while building application, we’ll be having two different options of choosing runtime. 1st is the full blown runtime as 4.5.1 or greater than that or 2nd option we can have cloud optimized runtime also called core CLR. Here, all the pieces like JIT Compiler, Garbage Collector are packaged and designed keeping high throughput and low memory consumption in mind. And now the application can have this cloud optimized environment embedded with the application which makes it easier to have true side by side version and by embedded it means you can deploy the .net framework by copying the nuget package. So, the idea behind this cloud version of .NET runtime is; it should be platform independent which means it can also run on MAC and LINUX machine.
Another great fact about the new changes in ASP.NET 5 is the unification. So, now
MVC 6 = ASP.NET MVC + WEB API
In MVC 6, WEB API is merged with MVC. This means we will now have one set of controller class, one set of attributes, model binders etc. Also, it no longer relies on the namespace system.web which means it is easy to self host and run the core CLR. Now, with these changes in place it doesn’t mean that your existing projects won’t work in VS 2015; It will work as smooth as it was in earlier versions. Now, lets go ahead and start the demo. I already have RC version of VS 2015 installed on my 2ndry machine. Lets go ahead and create new project
now, the below window is very much familiar to previous version. Here, i am interested in the new templates introduced. Hence, i am going to create a new project with ASP.NET 5 Website. This project will give me all the required components to run an app as shown below in the screen shot.
so, below shown window will be the new window for ASP.NET 5 project.
And when i run the same, it will produce me the below output. Very traditional MVC APP.
One point to also note that now folder organization in the file system and solution explorer is same as you can see in the below screen shots.
This also means whatever changes i do in the file system under src folder it will take effect in VS. Let’s create myImages folder in the file system with one image there. As soon as i added the image in the file system, it gets automatically synced with Solution Explorer.
Now, lets create one controller say GreetController but from the notepad; this is just to prove the point that we don’t need to build the app to take the code changes effect.
Now, after saving the same when i refresh the browser, then it will return me new controller’s output. so, this is called dynamic compilation.
Thanks for joining me for the 1st Edition of ASP.NET 5. We’ll delve further in coming topics. Till then stay tuned and Happy Coding.
Today, I would like to talk about the routing feature which is been introduced in the ASP.Net 4.0. here, in this case what happens basically, it will take an existing set of pages and re-write the urls in a frindly way. when i say friendly way it means user understandable, SEO optimized etc. so, the main enhancement which we see in asp.net 4.0 release is that routing module has been integrated by default for web forms. so, it has now become very easy to map the url request with the endpoints which we specify during configuring the same. so, what it exactly produce is come out with completely different kind of url scheme.
So, now see how does it work. well it uses the same pagerouteTable which ASP.Net MVC uses and in order for that to work, there is a handler PageRouteHandler which is automatically installed in ASP.Net 4. so, it’s job off course to dispatch requests onto pages. and the other interesting which is also included with this, is new function of RouteCollection is RouteCollection.MapPageRoute. basically, it defines the route. so, these things are pre-requisites for re-architecting the url scheme of the site.
now, in order to bring in routing i need to write the same in global.asax file. below, you can see the definition of MapPageRoute function.
but, here is catch i need to do one more configuration for running the same in IIS, i need to tell IIS to run managed Modules, otherwise, it would result me 404. here, it worked because i ran the same from my file system. so, we can instruct IIS from the web.config file by adding a simple entry as shown below.
so, the above instruction will make sure, that it will pickup the managed module installed for routing engine in ASP.Net 4.0. so, these are the basics. now, let’s focus on certain key points like ordering of route entries. This is very crucial because the 1st match is going to win.
Other important thing is that physical file will still take the precedence over route tables. so, it means using routing doesn’t change the existing functionality of ASP.Net means page based traversing, this will always remain as it is.
Another important thing is parameterized routes. it’s very much like query strings. so, rather than using query string, here we’ll be using segments of url, which is preferable as it is less prone to be hacked and understood by the hackers.
so, let’s see parameterized inputs. so, for this let me add one blank label on the page and the intention is just to grab the parameter value on the page load itself and the way i grab the value from the parameter is using the Page.RouteData to extract the data passed in the parameter like below
so, as you see above, this is 3 steps technique. but the crucial thing is route definition and fetching the same. however, you could also map the same to 404 url, in case there are certain values coming which doesn’t satisfy the scheme.
so, with this i would like to wrap this. Till then say tuned and happy coding.
Just for the sake of simplicity, i thought to blog about New Client Id Mode which is been incorporated in the ASP.Net 4.0 Version. So, Basically Client ID Mode lets you control Client Id’s of the server controls. It basically comes with 4 different flavors. These are
1) AutoID:- This one is the same as on 3.5 version or earlier one
2) Static:- What you type, that is going to be used.
3) Predictable:- Basically, concatenates the naming containers which one can set with new properties.
4) Inherit(Default):- So, this is the default one. This basically relies on whatever immediate parent specifies.
so, why basically client id controls are really important?
Hmmm, that’s because, the gradual shift of web programming towards client side like with the inclusion of jquery libraries, other 3rd party JS libraries, where in you need to couple the controls on the rendered page or before rendering with certain activity, may be to validate them or tweak the controls during load time, i mean whatever, but for handling the same you should be familiar with the naming conventions of the rendered client ids.
So, let’s go and try out Client ID Mode. So, am going to test the same with a very basic sample Asp.Net website template.
Now, here in the above case i have set the clientIdMode=”AutoID”, which means the page will behave as it used to be in 3.5 version and earlier. So, now see that what kind of identifier was generated for the same.
see, this was the identifier which is being generated. so, @ this stage if i have do certain client side validations on these kind of ids, this is going to be real mess.
now, look @ the behavior in the default mode which is predictable mode.
since, am using master page, hence it took the content page name and concatenated with my label name, so this is somewhat very obvious which we can take into account and write the script terminology based on that.
However, my personal favorite is clientIdMode =”‘Static” which means whatever am typing as my identifier name, same is going to be rendered in there on the page as shown below.
and in case of inherited, it is going to produce the same result as it produced in the case of Predictable, because i have set the same @ top level. hence that is going to inherit from the same. so, with this I would like to wrap this. Thanks for your time. Till then, stay tuned and happy coding.
Today, in this discussion, i would like to stress upon View State improvements which is done in ASP.Net 4.0 series. So, it says basically, that view state can be disabled completely @ page level, but it can be enabled @ control level. so, it means you can disable the same @ top level and re-enable the same control level selectively. Initially, it was like disable view state or enable view state, means all or nothing.
so, let’s get started, let’s explain the same visual studio itself.
so, here i have added 2 things, a simple label just to track the no of page loads and one table just to make the view state size huge.
so, when i do every time postback, it will increment the value by 1. so, viewstate is basically a mechanism for remembering the control state.
so, as you see upon submitting that counter gets incremented, but when i saw the page source, i could see the real mess, here the thing, is on every subsequent request viewstate of the page is getting incremented and hence will cause page to load slow. this chunk is basically base 64 encoding which is basically view state encoding mechanism. so, basically what we used to do @ 1st attempt to disable the viewstate @ the page level likewise
and that would certainly solve the problem as this will disable completely viewstate from the page and page gets optimized, bang we achieved to the solution. but, we certainly didn’t want this. we wanted to keep track of no of clicks, how would we achieve then, hmmm if you try doing enableViewstate=”True” @ control level, that would not work. so, what we would do instead, we would use ViewStateMode property as shown below.
now, this will solve the problem. Now, new view state will look like this
so, with this i would like to wrap, till then stay tuned and happy coding.
991 total views, 1 views today
Subscribe For Latest Updates!
Signup for My View newsletter and get notified when I publish new articles for free!