Monday, October 26, 2009

User Account Control Settings in Windows 7

One of the nice features in Windows 7 is the possibility to tell the system weather it should communicate to you about the changes in your system that applications are attempting to do or not. At home I share my PC with my wife and my children. I surely want to know about the things where as they do not care about these messages. So I can use this tool to sort out for each user.
The tool is accessible through the ControlPanel->AllControlPannelItems->ActionCenter->ChangeAccountControlSettings

Friday, October 23, 2009

Test Your Pages

Some handy tools to check you pageloads:
- HTTPFox : obviously for FireFox, but not available for new version of FF at this time :-(
- HttpWatch a free tool (can upgrade to professional) works on both IE8 and FF as addin. It rocks
- www.webpagetest.org a free website that tests your page from a remote location. They provide three remote location to initiate the test which makes your test very natural.

Wednesday, October 21, 2009

Run As Administrator

If you have an application you want to run it as administrator you could use the following command for it:

runas /user:Administrator MyApp


For things like Cisual Studio 2008 you can change the properties of the shortcut, and in the Advanced Properties check the Run as administrator checkbox.

VS 2008 JavaScript Intellisense

in his artikel about "VS 2008 JavaScript Intellisense" sdescribes the using of WebServices and AJAX Behaviors within javascripts:

http://weblogs.asp.net/scottgu/archive/2007/06/21/vs-2008-javascript-intellisense.aspx

Friday, September 25, 2009

How to stick the footer to the buttom of the page

As usual there are more roads leading to Mekka. This is one way of getting the same result without any scripts. It uses a simple cascading stylesheet:


div#footer
{
   clear: both;
   padding: .5em 1em;
   border-top: 0px solid #ccc;
   text-align: center;
   padding: 0 0 0 0;
   margin: -20px 0 0 -100px;
   position: fixed;
   left : 50%;
   top: 100%;
}

Monday, September 21, 2009

IIS Url Forwarding

One easy way of forwarding can be stablished from within the Web.config in the system.web section:


<urlmappings enabled="true"><blockquote><p><urlmappings enabled="true">
<add mappedurl="~/default.aspx?parm1=1" url="~/home">
<add mappedurl="~/Products.aspx" url="~/products">
<add mappedurl="~/Product.aspx?id=1" url="~/product">
</urlmappings>

How do I secure my browser - Part

I came across a web address that has phishing software. It was www.secure-logins.com. I figured out that this is not the only address in tis domain that has the worm, any address ending to the same domain is doing the same harm. So I had to find a way to stop all the requests going from my browser (or even better from my house) to this domain. This is what I did:

I. Tell your browser never go to that domain.
II. let your router know that this domain should be filtered.

Although the second way is enough to stop the worm but I thought some people might not have the feature in their router to do that, so I also mentioned the first one.


1. In the Internet Explorer go to Menu Tools->Internet Options and when the Internet Options pops up click on the Security tab.
2. You will see different zones. The important zone is : Restricted sites. Click on it.
3. Once you selected the Restricted sites click on the Sites button. This will pop up another window called Restricted Sites which holds a list of sites that you don't want your browser coincidently or willingly go there.
4. In th text box under "Add this site to the zone:" type the following:
*.secure-logins.com
5. Press the Add button and you will see that the address is added to the list
6. Press the Close button and you will be back to the Internet Options.
7. Click OK,
that's it

My router is a D-Link and have an option to filter any requests going to a specific address from any machine at my home. You should check your router's website which is often to e accessed by http://192.168.0.1
In the Advanced menu you will find a link to go to Website Filter. When you get there you will see an empty list where you can add your preferences. The 'Website Filter' option allows you to set up a list of Web sites you would like to deny through your network.
Add the same address there:

thats all.

Friday, August 21, 2009

Tip To Log

We often like to know what happens in a procedure and also we like to figure out if we see something in the log, where in the code it happened. Therefore it is handy to start and end each procedure with log. To do this we can put a small generic code like this


Trace.WriteLine("Beginning with " + System.Reflection.MethodInfo.GetCurrentMethod().Name);

it will work just fine

Monday, August 10, 2009

Linq-To-SQL and WCF

WCF works on the objects like disconnected records. The object that is passed to the client is not the same as the one the is about to update. Therefore Linq does not know about the changes made to the record. As a result Linq will not do anything when calling the SubmitChanges.

To sort out this problem we need attach the instance record again to the list in the context:

context.GetTable().Attach(instance, true);

just before we call the SubmitChanges. But this is not always possible. I got the following error when calling this:

An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.

The simple way of sorting this out was giving the ID field of the record the attribute of

IsVersion=true

This way Linq allows me to attach the existing instance and generate an UPDATE sql-statement.


See Also: http://www.west-wind.com/Weblog/posts/135659.aspx

Wednesday, July 15, 2009

Using Linq-To-SQL classes as DataContract in WCF

Coming accross a nice tutorial from Jesse Liberty

He describes the trick to get the Link-To-SQL data classes generated to be consumed as DataContract. In his document he points out that you need to set the Serialization Mode property of the dbml surface to Unidirectional.

Friday, July 10, 2009

Common Buses and their Max Bandwidth

Nice article from: http://networking.ringofsaturn.com/PC/pciexpress.php

Bandwidth
PCI Express in all it's flavors: 1x, 2x, 4x, 8x, 16x and 32x all have much greater bandwidth than basic PCI.

Common Buses and their Max Bandwidth
PCI 132 MB/s
AGP 8X 2,100 MB/s
PCI Express 1x 250 [500]* MB/s
PCI Express 2x 500 [1000]* MB/s
PCI Express 4x 1000 [2000]* MB/s
PCI Express 8x 2000 [4000]* MB/s
PCI Express 16x 4000 [8000]* MB/s
PCI Express 32x 8000 [16000]* MB/s
IDE (ATA100) 100 MB/s
IDE (ATA133) 133 MB/s
SATA 150 MB/s
Gigabit Ethernet 125 MB/s
IEEE1394B [Firewire] 100 MB/s

Tuesday, June 16, 2009

using UriTemplate

Copied from MSDN:


The UriTemplateTable class provides a mechanism for managing a collection of UriTemplate objects. This makes it easy to call Match on the table to find all templates that match the supplied Uri. Alternatively, you can call MatchSingle to ensure it matches only a single UriTemplate in the table.

Uri baseUri = new Uri("http://contoso.com/bookmarkservice");
UriTemplate uriTemplate = new UriTemplate( "users/{username}/bookmarks/{id}");

// generate a new bookmark URI
Uri newBookmarkUri = uriTemplate.BindByPosition(baseUri, "skonnard", "123");

// match an existing bookmark URI
UriTemplateMatch match = uriTemplate.Match(baseUri, newBookmarkUri);
System.Diagnostics.Debug.Assert(match != null);
Console.WriteLine(match.BoundVariables["username"]);
Console.WriteLine(match.BoundVariables["id"]);

Friday, March 27, 2009

Catch the Session Expired case

The project I am working on requires to show a nice custom error page to the user when the session is expired. I searched a bit on the internet and came up with a good solution in forums.asp.net which I worked it out as follows:

As mentioned in the forum you need to implement an IHttpModule and redirect the context'e AcquireRequestState event to your method which goes this:

        void Application_AcquireRequestState(object sender, EventArgs e)
{
if (HttpContext.Current.Session != null && HttpContext.Current.Session.IsNewSession)
{
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies["ASP.NET_SessionId"] != null)
{
HttpContext.Current.Session.Clear();
HttpContext.Current.Response.Redirect(
"/Errors/SessionTimeout.aspx", true);
}
}
}

}


As you can see I clear the session before redirecting to the SessionTimeout.aspx. The reason for that is that I want the user have a choice of going to login screen by providing a link in the SessionTimeout.aspx. And the login requires a session state unlike the SessionTimeout.aspx that has the attribute EnableSessionState="False" 





Friday, March 20, 2009

URL properties of Request to ASP.NET

The following attributes are some of the usefull properties of the URL object. I use the following url to send my request to localhost:


http://localhost/Test/Asghar.aspx?test=fine


And I get the following results:

AbsolutePath = /Test/Asghar.aspx
AbsoluteUri = http://localhost/Test/Asghar.aspx?test=fine
Authority = localhost
DnsSafeHost = localhost
Fragment =
Host = localhost
HostNameType= Dns
IsAbsoluteUri = True
IsFile = False
LocalPath = /Test/Asghar.aspx
OriginalString = http://localhost:80/Test/Asghar.aspx?test=fine
PathAndQuery = /Test/Asghar.aspx?test=fine
Port = 80
Query = ?test=fine
Scheme = http
UserEscaped = False
UserInfo =

And the code to do it is as followes:
    AbsolutePath = <%= System.Web.HttpContext.Current.Request.Url.AbsolutePath %><br />
AbsoluteUri = <%= System.Web.HttpContext.Current.Request.Url.AbsoluteUri %><br />
Authority = <%= System.Web.HttpContext.Current.Request.Url.Authority %><br />
DnsSafeHost = <%= System.Web.HttpContext.Current.Request.Url.DnsSafeHost %><br />
Fragment = <%= System.Web.HttpContext.Current.Request.Url.Fragment %><br />
Host = <%= System.Web.HttpContext.Current.Request.Url.Host %><br />
HostNameType= <%= System.Web.HttpContext.Current.Request.Url.HostNameType.ToString() %><br />
IsAbsoluteUri = <%= System.Web.HttpContext.Current.Request.Url.IsAbsoluteUri %><br />
IsFile = <%= System.Web.HttpContext.Current.Request.Url.IsFile %><br />
LocalPath = <%= System.Web.HttpContext.Current.Request.Url.LocalPath %><br />
OriginalString = <%= System.Web.HttpContext.Current.Request.Url.OriginalString %><br />
PathAndQuery = <%= System.Web.HttpContext.Current.Request.Url.PathAndQuery %><br />
Port = <%= System.Web.HttpContext.Current.Request.Url.Port %><br />
Query = <%= System.Web.HttpContext.Current.Request.Url.Query %><br />
Scheme = <%= System.Web.HttpContext.Current.Request.Url.Scheme %><br />
UserEscaped = <%= System.Web.HttpContext.Current.Request.Url.UserEscaped %><br />
UserInfo = <%= System.Web.HttpContext.Current.Request.Url.UserInfo %><br />
<hr />

Saturday, January 31, 2009

Read CSV file into LINQ

This article is based on the great book of LINQ in Action. I am learning so much from it and I would like to keep a note of some handy subject from the book while not disturbing any copyright of ther authors. For the full story please buy the book from http://www.manning.com/LINQinAction.

 
using (StreamReader reader = new StreamReader("books.csv"))
{
var books =
from line in reader.Lines()
where !line.StartsWith("#")
let parts = line.Split(',')
select new {
Title = parts[1],
Publisher = parts[3],
Isbn = parts[0]
};

// use the books here ...
}

Join And Group Tables

This article is based on the great book of LINQ in Action. I am learning so much from it and I would like to keep a note of some handy subject from the book while not disturbing any copyright of ther authors. For the full story please buy the book from http://www.manning.com/LINQinAction


Group Join

from publisher in SampleData.Publishers
join book in SampleData.Books
on publisher equals book.Publisher into publisherBooks
select new { Publisher=publisher.Name, Books=publisherBooks };

This is a group join. It bundles each publisher's book as sequences named publisherBooks. This new query is equivalent to this one:

from book in SampleData.Books
group book by book.Publisher into publisherBooks
select new { Publisher=publisherBooks.Key.Name, Books=publisherBooks };



Inner Join
An inner join essentially finds the intersection between two sequences. With an inner join, the elements from two sequences that meet a matching condition are combined to from a single sequence.

from publisher in SampleData.Publishers
join book in SampleData.Books
on publisher equals book.Publisher
select new { Publisher=publisher.Name, Book=book.Title };



Left Outer Join
When we want to keep all the elements from the outer sequence, independently of whether there is a matching element in the inner sequence, we need to perform a left outer join.

A left outer join is like an inner inner join, except that all the left-side elements get included at least once, even if they don't match any right side elements.


from publisher in SampleData.Publishers
join book in SampleData.Books
on publisher equals book.Publisher into publisherBooks
from book in publisherBooks.DefaultIfEmpty()
select new {
Publisher = publisher.Name,
Book = book == default(Book) ? "(no books)" : book.Title
};

DefaultEmpty operator supplies a default element for an empty sequence.
DefaultEmpty uses the default keyword of generics. It returns null for reference types and zero for numeric value types. For structs, it returns each member of the struct initialized to zero or null depending on whether they are value or reference types.

Cross Join
A cross join computes the Cartesian product of all the elements from two sequences. The result is a sequence that contains a combination of each element from the first sequence with eacht element from the second sequence.

from publisher in SampleData.Publishers
from book in SampleData.Books
select new {
Correct = (publisher == book.Publisher)
Publisher = publisher.Name,
Book = book.Title
};