Monday 20 April 2015

ASP.NET - Current Page Url with QueryString

You might need to extract different values from url.
It might be the path or the current page or values in the querystring.
Here is a simple reference to different uri based info available to you out of the box.


Response.Write( Request.Url.Host );
Response.Write( Request.Url.AbsolutePath );
Response.Write( Request.ApplicationPath );
Response.Write( Request.Url.AbsoluteUri );
Response.Write( Request.Url.PathAndQuery );


The above sample "Request.Url" is when you use in ASP.NET Code behind.
If you use it within a class library then you will have to refer it as ""HttpContext.Current.Request.Url".

Sunday 12 April 2015

IIS - Restrict IP Address Range

Allowing and restricting visits from certain IPs or IP ranges can be easily done on IIS.
Working with a simple IP is easy. Working on an IP range is a bit more complicated.
We will discuss about it here. I will discuss about the restriction case and you can follow the same method for "Allow IP " case also.
Follow the below steps:
  1. Make sure "IP Security" feature is installed on your IIS server machine.

    • Goto Control Panel > On Left Pane select "Turn Windows features on or off".
    • On Windows Features window, select "IP Security" and click "OK".
    • Installing this you might be prompted for a reboot.

  2. Now browse to your website on IIS (Internet Information Services Management Services Console) and Open (Double Click) "IP Address and Domain Restrictions".

  3. Right Click > Select option "Add Deny Entry".

  4. Enter the IP Address Range and Subnet Mask to restrict.
    • In the above example all IPs in the range: - will be blocked.
    • To help you calculate the subnet mask, use the tool: