Categories
ASP.NET How To Tips Visual Studio

How to get user IP address in ASP.NET

There can be number of ways security and auditing can be implemented in any application. It can be done at Application Level, or at Application Server level or at Database Server Level. And I think best practice is to take advantage of all 3 based on user requirement, as we all know that having little “extra” security always generates burden on system as a whole. Actually it really depends on user requirement, for example some simple quote request form will not have that security features as any bank transaction form will have. (you got the point, right ??)

One way to track user is by IP address. IP stands for Internet Protocol which is basically used to relay (send/receive) information (in form of packets) to network (or internet). It lives at Internet Layer in Protocol Stack. And when any machine is connected in network (here I will use network and internet terms interchangeably for sake of simplicity) it is assigned a unique IP address based on which that machine can be identified. For example 74.125.226.144 will take us to www.Google.com which is more human readable name which is actually an address of a computer that is running Google search engine. (in reality they never use static IP for security, I think it is some sort of proxy server that route requests to main server, this technology has changed very much since the invention of internet) … oki, back to main topic. In short if we get IP address of user, we can always identify user from that because in enterprise network usually each machine is assigned to that person only.

Categories
How To SQL Server Tips

Remote Debugging in SQL Server Management Studio …

If you are a developer you know very well that a good programmer is not someone who can write fancy code but someone who knows how/when/where to press F9-F10 smile_tongue no offence. And it is equivalently true for SQL Server as well. Front end used to manage SQL Server instance is called SQL Server Management Studio (aka SSMS, my current project requires to me to be very familiar with many acronyms and aliases so I kind of love acronyms) … and debugging can be very very handy tool when you are developing some sort of Stored Procedure, Function, View or any sort of super complex query. It gives you insight of how your code works at every step and you can easily troubleshoot your code if something is wrong.

If you are have installed instance of SQL Server on local machine then this post is not for you. But if you are a developer at some enterprise where you are usually not allowed to have separate installation of SQL Server on your local machine. And you are usually using SSMS installed on your workstation to connect to Dev. server or something like that. In that case it could be real issue for you if you have not done before. No matter how much developers try, there has been always problem with error messages. I mean beyond some limit error messages can’t be displayed in much friendly text.

To be able to run remote debugger on your workstation, it is two part process. First you need to configure firewall of your workstation and then you need to add exception at firewall of your Database Server. And in general both can be done by yourself if you have sufficient admin rights.

Categories
Babbling Bugs Me Software Wordpress

Joining the Band !!!

And yes … this is my very first post from my Android phone. In recent years these so called “smart phones” has really changed what we do online & on phone. Devices have become so powerful that once average PC was 😉 !!!

Actually I am really glad that this good folks (makers of wordpress ) have also made a great app for android which I am using ryt now to post this post … I hope that in future I won’t get this honor to post on my blog because I think one of the biggest dis-advantage of these smart phones is their keyboards. I really miss those big ,squezy keys who never feel bad if I sometimes press-hit hard ..

But I am using my phone instead of my machine because AVG Internet Security has literally caused BSOD on my Win 7 machine !!! I mean this is really heights of bad update for any software. Being old player in AV market I am really shocked … luckily I have dual booted my system with ol’ reliable linux so after this post I will dig more on net from that system or may be watch HULU and go to bed :-P…(

heyy, I have to keep track of missed episodes of my fav. series …
So I end here …

Categories
ASP.NET Bugs Tips

Ajax Control Toolkit and IE 9 Runtime Error

You guys may be thinking that what the hell is wrong with this guy. First he doesn’t write much and even if he write he always cries about errors he get while working on his things !!! Its always he , he and he … with error error and errors only … but fact is no matter how much I try to code well, I frequently get really really weird errors and being my log, I like to keep track of these errors in this blog.

Oki, so another error today. As you might know, I like to taste things before they release. Actually, I like that because it keeps me updated with new stuffs in technology of present time. So keeping that tradition alive, I had installed IE 9 Beta in my machine from few months now. Just today I was working / playing with my code as usual. actually it was an old program that I was rewriting to do some improvement in functionality. So, after making some changes I tried to run the program, but I got something like this as error Microsoft JScript runtime error: Invalid set operation on read-only property.

I tried to f9 the code and at one point it was showing some that it need some files from my AJAX Control toolkit (I was using many controls from AJAX Control toolkit). But I was not getting any idea what it is really missing. It was showing me error that we see when we are using component of AJAX Control Toolkit but not including Toolkit Script manager. But I have already included Toolkit Script manager into program, and that actually made me confused about error.

Categories
.NET ASP.NET IIS Tips

.NET Framework 4 and Could Not Load Type ‘System.ServiceModel.Activation.HttpModule’ Error …

 

So, day before yesterday I was working on some app. And I deployed it on my IIS (v7.5) server. The deployment process went very well without any sort of troubles. But when I tried to run that application from my web browser I got loads of error. And I found that the main error was something like this,

Could Not Load Type ‘System.ServiceModel.Activation.HttpModule’

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

Description: An unhandled exception occurred during the execution of the current Web request. Review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

 

With little googling, I found that I was not the first victim of this error !!! And after few clicks I finally found the reason and solution for this error.

The Reason: If you have installed IIS AFTER installing .NET Framework 4 (in my case) then it won’t get register with IIS and so when you run the app that is built on .NET v.4  by deploying it won’t work and will give you above mentioned error. And the solution is next.

Categories
SQL Server Tips

IDENTITY key is not itself set to be Primary Key or Unique Key ??

If you have done any sort of development in database you might be familiar with IDENTITY column. It basically gives you a column which increments it self to a given value (aka Seed and Increment). General syntax for IDENTITY is,

IDENTITY [ ( seed , increment ) ]

It is basically a “Plan B” for tables where you can’t find any candidate key. By declaring a column having IDENTITY Key, you can get your self out of dilemma of what to do and how to do when your client want you to have flexibility to add any type of redundant data with still ability to distinguish between different entries !! Or simply to evade many to many (m:n) relations between tables. But as we know, it is not a good practice to simply assign an IDENTITY key and jerry rig the problem, but something we don’t have a choice (do we ever have any ?? smile_wink) …

Anyways, today’s post is about what the title says. Some people (like one of my friend) think that when we declare an Identity column, it itself becomes Unique key (because the IDENTITY key always generates UNIQUE Numbers) .. and hence it can be used as a FK even though we have not made it Primary Key or even not include UNIQUE keyword in its definition !! I have prepared a little experiment to demonstrate this …

Categories
ASP.NET How To Visual Studio

Using Cookie in ASP.NET to store temporary data

Today’s post is about how we can use Cookie to store data temporarily. While working on one project for frontend application my client told me that they need some sort of functionality so that user somehow can temporarily store some of the form data and can use the same data when they run the application again. And without any hesitation the first thought came in my mind was to use cookie for this purpose.

I have written a simple code to demonstrate the use of HTTPCOOKIE to create cookie and then use the cookie to retrieve information from it. It is a simple two textbox , buttons and a label form. It accepts name (last and first) from user and sets it into cookie and then retrieves it from cookie in event of button click (if present, else it displays message that it has not found any cookie !!)

The backend code is as follows,