Sid's Blog

( life => life.Make It Better ))

How to Get UnAuthorizedAccess (401) HTTP Response When Using ASP.NET Forms Authentication and AJAX?

| Comments

I’ve a ASP.NET MVC application that uses FormsAuthentication and this application gives single page application experience to users after a user is authenticated where it uses AJAX for all HTTP requests.

The log out action that I have works fine if user uses the logout button in the user interface and the click handler than performs a HTTP POST to Logout action in Account controller.

Today,I was testing some other feature by setting 1 minute timeout for forms authentication in web.config. After a minute, when I performs a POST action to view a different view in my application, I was shown the user login page as set in the web.config under forms configuration. But I was not able to understand why is this happening. Later I figured out that the FormsAuthentication is doing its work and it detects that this user is not authorized. It then redirects the user to the login url as defined in the configuration.

Cookie Issues With Internet Explorer.

| Comments

Recently, I was working on a ASP.NET MVC 5 web application that was using cookies to store some user specific data. This was done by first serializing that object into forms authentication ticket and then encrypting this serialized data and setting this encrypted value to a cookie.

Unit Test and Test Driven Development in ASP.NET MVC Application

| Comments

This article aims to summarize the concept of testing which can help you while writing tests using any framework out there. I will be writing more on this topic and will also attach any relevant demo applications on github. 

Types of Testing

There are many types of testing that you may want to apply to your application, namely:

  • Unit Test & Test Driven Development (TDD)
  • User Interface Testing
  • Integration Testing
  • Acceptance Testing 
  • Performance Testing
  • Accessibility Testing
  • Security Testing

Some Facts About All the Programmer or a Software Developer

| Comments

No matter where you are in your software development career or what technologies you work with, there are couple to things we all have in common:

  • Education (Everyone needs to go for education but the nature of that education can differ.)
    • Knowledge (the things we know)
    • Skills (how we use the knowledge)
    • Judgement (Choosing the right approach)
  • The challenge is – There are always new platforms, new tools, new languages as our field is growing rapidly.

In case of any other profession, if you stop learning, things will still work. But in fields like software development and information technology, we need to make learning as our habit and a passion too as if you don’t do it, your skills will be less valuable in the IT market.

Career of a Software Developer and Some Strategies to Survive

| Comments

If you are an software developer by profession or have hobby to develop in some languages, I guess you spend most of your time working on different technologies and updating your skills either by attending conferences, books and other sources. There are many things to learn and by the time we learn some of them, we again have lots of other new things in queue, that never ends! It is sometimes very difficult to how to work in such environment and keep learning and updating your skills. Everyone has this issue but very few talk about this! Geeks can talk a lot about comparing different technologies or the competition going on between Microsoft, Google or any other organisation. But wait, is this all a software developer can think of or should do? No, we are not taking care of many important factors that I am going to talk about here.

What if I Don’t Have SQL Express Installed?

| Comments

 what if I don’t have SQL Express installed?

If you don’t have SQL Express installed and running, you may have got the following error when your code tried to read or write some data:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Blah blah blah… No problem! You can quickly switch to use the new SQL Server Compact – a lightweight, in-process database – without having to download or install anything manually. Simply add SQL Server Compact to your project by issuing the following command in the Package Manager Console:

Install-Package EFCodeFirst.SqlServerCompact

Extract Key/values From FormCollection in ASP.NET MVC Action Method

| Comments

To avoid you from having to chase for the same information: here’s how you extract key / value pairs from the FormCollection that comes as an argument in an ASP.NET MVC action method:

public ActionResult Create(FormCollection formCollection){ foreach (var key in formCollection.AllKeys) { var value = formCollection[key]; // etc. } foreach (var key in formCollection.Keys) { var value = formCollection[key.ToString()]; // etc. }}