views:

1569

answers:

4

Are there any prebuilt modules for this? Is there an event thats called everytime a page is loaded? I'm just trying to secure one of my more important admin sections.

A: 

A little more information please; do you want to log IPs or lock access via IP? Both those functions are built into IIS rather than ASP.NET; so are you looking for how to limit access via IP programatically?

blowdart
A: 

You can use the following to get a user's IP address:

Request.ServerVariables["REMOTE_ADDR"]

Once you have the IP you will have to write something custom to log it or block by IP. There isn't something built in to asp.net to do this for you.

AaronS
+2  A: 

As blowdart said, simple IP Address logging is handled by IIS already. Simply right-click on the Website in Internet Information Services (IIS) Manager tool, go to the Web Site tab, and check the Enable Logging box. You can customize what information is logged also.

If you want to restrict the site or even a folder of the site to specific IP's, just go to the IIS Site or Folder properties that you want to protect in the IIS Manager, right click and select Properties. Choose the Directory Security tab. In the middle you should see the "IP Addresses and domain name restrictions. This will be where you can setup which IP's to block or allow.

If you want to do this programatically in the code-behind of ASP.Net, you could use the page preinit event.

CodeRot
Is there anything like application Error that is called everytime ANY page is loaded? that's what i'm really looking for.
A: 

"Is there an event that's called everytime a page is loaded?"

Page_Load might be what you're looking for.

However, and I'm really not trying to be mean here, if you don't know that, you probably shouldn't be trying to secure the app. You're just not experienced enough in .Net

I'm sure you're great at what you do, in whatever platform you're experienced in. But .Net WebForms isn't your forte. This is one of those times when you should back off and let someone else handle it.

chris
The question was a little too abstract for you to understand. I was looking for more of a global handler like Application_Error. As far as languages go -- .net is prolly the easiest of the compiled language and i really don't have problems with it unless it's some obscured knowledge.
Well,I'll put the blame on the wording of the question. You'll see that CodeRot interpreted the question exactly the same way."Is there an event that's called every time a page is loaded?" Your rephrasing in the comment to his post is much more clear.
chris