A Look At The ASP.NET Core Pitfalls

When you intend to redirect after a Post, following the Post-Redirect-Get pattern but your previous view is constructed using a route parameter, then it would be sent to the redirect action too.

A Look At The ASP.NET Core Pitfalls

For instance, you are responding to a request for /Filter/Smartphone, where Smartphone is a route parameter, you Post it to some other controller action and at the end, you redirect to the Index action making use of the RedirectToAction method:

Return this.RedirectToAction(name of(Index));

The browser would issue the GET request for Index but takes the Smartphone route parameter, which is not fine.

The solution is to pass a routeValues parameter to RedirectToAction that do not have any of the possible route parameters. One way to do it is that you can create a dictionary with all action parameters zeroed:

return this.RedirectToAction(nameof(Index), MethodBase.GetCurrentMethod().GetParameters().ToDictionary(x => x.Name, x => (object) null));

The solution to do this automatically lies in the MethodBase.GetCurrentMethod() method. This way, you can surely avoid unwanted route parameters during your next request.

In case you wonder, passing null, a dictionary without object or entries would not work, the only other way is to pass an unknown value with the parameters set to null.

That’s it for now!

If you want to upgrade yourself to the basics and concepts of Dot Net Course and improve through Dot NET training program; our institute, CRB Tech Solutions would be of great help and support.

We give a well-structured program for the best Dot Net Course. Among various good institutes of dot net training and placement in Pune, CRB Tech has developed its own identity.

Happy Coding!


An Introduction To Interception In EF Core

Entity Framework or EF Core is a lightweight, could be extended, and a cross-platform version of the commonly known Entity Framework data access technology.

EF Core is an object-relational mapper (O/RM) that allows .NET developers to work with a database that uses .NET objects. It removes the need for much of the data-access code which developers usually require to write codes. EF Core supports several database engines.


Presently, Entity Framework Core yet does not have all of the attributes provided by pre-Core versions. One of the features is an ability to intercept questions, something which was offered by the IDbCommandInterceptor, IDbCommandTreeInterceptor interfaces.

The EF Core 2.0 has an interception at the SQL level, and you can only get to this in a rather complicated way, via the DiagnosticSource mechanism. Here we shall discuss on how to create a class with two methods, as shown below:

Public class CommandListener



public void OnCommandExecuting(DbCommand command, DbCommandMethod executeMethod, Guid commandId, Guid connectionId, bool async, DateTimeOffset startTime)



[DiagnosticName (“Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted”)]

public void OnCommandExecuted(object result, bool async)




You will require the Microsoft.Extensions.DiagnosticAdapter NuGet package to assemble this.

The methods can be hooked to EF Core as shown below:

var listener = ctx.GetService<DiagnosticSource>();

(listener as DiagnosticListener).SubscribeWithAdapter(new CommandListener());

Here, ctx is a DbContext, and it is being tried to access its registered DiagnosticSource service, which is a DiagnosticListener. You need to add a subscriber, and that’s it!

From the OnCommandExecuted method you can summon these methods whatever you choose, as long you keep the [DiagnosticName] features, the result parameter would contain either a scalar, a number or a RelationalDataReader object a sync, and would tell you exactly what version of the method was implemented.

OnCommandExecuting is quite amazing because there you can get an access to the DbCommand which is on how to implement the SQL command and can edit its SQL or parameters.

There are other mechanisms of interception as well, like the IQuerySqlGenerator and IQueryCompiler, to be covered later.

With this, we conclude. Keep coding!

If you want to enhance yourself in basics and concepts with Dot Net Course and improve yourself through Dot NET training program; our institute would be of great help and support.

We give a well-structured program for the best Dot Net Course.Among several good institutes of dot net training and placement in Pune, CRBtech has created a niche for itself.

Code source: Development With A Dot

Best Forums For General Discussion

In now a days forums are much more used for generating backlinks, traffic etc.

The general discussion forum list is as follows :


  1. General Discussion – Giant Bomb

  2. Forummantra – A Place Where You Ask ! You Answer !

  3. Free Board: General Discussion Forum | GoldandBlack.com

  4. General Discussion – Supercell Community Forums

These are the best forums, by this you can generate good quality traffic as well as generate backlinks also.

I hope this will be helpful for the beginners as well as the experience one.

Thank You.



The Journey Begins

Thanks for joining me!

Good company in a journey makes the way seem shorter. — Izaak Walton