My preferred method for Active Directory administration with .NET is to use the Directory Services API. First off, add a reference to the System.DirectoryServices dll in your project, then add the following to the top of your class to reference that API.
using System.DirectoryServices;
1. Create the Directory Entry object for the user:
DirectoryEntry deUser = new DirectoryEntry();
2. create the object for the parent container for the user:
objUsersContainer = new DirectoryEntry(@"LDAP://ou=Users,dc=mydomain,dc=com");
NOTE: You must be authenticated at this point with an account that has permissions to create Active Directory users on your domain. If you wish to explicitly pass credentials to this object, you can use the following:
objUsersContainer = new DirectoryEntry(@"LDAP://ou=Users,dc=mydomain,dc=com", "userid", "password", AuthenticationTypes.Secure);
3. Bind the user object to its parent container:
deEntry = objUsersContainer.Children.Add("cn=User Test", "user");
NOTES:
1st Parameter: "cn=User Test". This cn value must be unique to this container, so use some kind of method for finding a unique cn. This can be done with the Directory Searcher. Google this or wait until I add to another post: ) Or comment to this post...i'll help out.
2nd Parameter: "user". This specifies what type of object your child is.
4. Set the required properties:
deEntry.Properties["samaccountname"].Value = "newuserid"; //This is the user's login id
deEntry.Properties["displayname"].Value = "User, Test"; //This is the text that will display in a global address list
5. Save you're changes!:
deEntry.CommitChanges();
There it is! The account should exist in your domain. However, this is most likely not all that need's to be done. The user still needs a password and be enabled to be able to log in and you may wish to set other properties on this account. My next post will cover these methods.
Friday, March 27, 2009
Tuesday, March 24, 2009
The loading gif problem (.NET)
If you've ever felt the need to use a loading gif , you may have run into a few problems.
Displaying the gif before the rest of page finishes loading isn't as simple a task as you would think. The best way I've found to do this is by dynamically writing javascript as the very first instructions of your Page_Load.
Response.Write("<div id="'mydiv'"> ")
Response.Write("Loading data...<img src="loading.gif" />")
Response.Write("</div>")
Response.Write("<script> var mydiv = document.getElementById('mydiv');</script>")
Response.Write("<script language="javascript">")
Response.Write("function StartShowWait(){mydiv.style.display = 'block';}")
Response.Write("function HideWait(){mydiv.style.display = 'none';}")
Response.Write("StartShowWait();</script>")
Response.Flush()
This basically creates a div tag which stores your loading message and the gif. The StartShowWait() function is called, which displays your loading gif and the Response.Flush() function renders this javascript code to your client before the rest of the page finishes loading. If you don't call Response.Flush(), your javascript code will sit on the server until the page is completely loaded.
In the HTML of your page, make sure you include the following javascript snippet to hide the loading gif once the requested page is completely loaded:
<script lang="javascript">
HideWait();
</script>
So are we done now? Depends on whether you want to do some more processing of data and redirect to another page. If you're using .NET, calling:
Response.Redirect("foo.aspx")
You will get a System.Web.HttpException: Cannot redirect after HTTP headers have been sent.
To overcome this, simple call another snippet of javascript to redirect the page and flush the response again:
Response.Write("<script language="javascript">location.href='foo.aspx';</script>")
Response.Flush()
Hopefully this will alleviate some headaches from trying to execute this simple task.
Displaying the gif before the rest of page finishes loading isn't as simple a task as you would think. The best way I've found to do this is by dynamically writing javascript as the very first instructions of your Page_Load.
Response.Write("<div id="'mydiv'"> ")
Response.Write("Loading data...<img src="loading.gif" />")
Response.Write("</div>")
Response.Write("<script> var mydiv = document.getElementById('mydiv');</script>")
Response.Write("<script language="javascript">")
Response.Write("function StartShowWait(){mydiv.style.display = 'block';}")
Response.Write("function HideWait(){mydiv.style.display = 'none';}")
Response.Write("StartShowWait();</script>")
Response.Flush()
This basically creates a div tag which stores your loading message and the gif. The StartShowWait() function is called, which displays your loading gif and the Response.Flush() function renders this javascript code to your client before the rest of the page finishes loading. If you don't call Response.Flush(), your javascript code will sit on the server until the page is completely loaded.
In the HTML of your page, make sure you include the following javascript snippet to hide the loading gif once the requested page is completely loaded:
<script lang="javascript">
HideWait();
</script>
So are we done now? Depends on whether you want to do some more processing of data and redirect to another page. If you're using .NET, calling:
Response.Redirect("foo.aspx")
You will get a System.Web.HttpException: Cannot redirect after HTTP headers have been sent.
To overcome this, simple call another snippet of javascript to redirect the page and flush the response again:
Response.Write("<script language="javascript">location.href='foo.aspx';</script>")
Response.Flush()
Hopefully this will alleviate some headaches from trying to execute this simple task.
new direction
I'm going to change the direction of my blog. I'm going to post solutions to various programming problems I've encountered. This blog will mainly serve as a reference for myself and hopefully it will help out a few people who have encountered the same problems.
Wednesday, November 5, 2008
Why I Didn't Vote for Obama
Before Barack Obama announced his bid for president, I was a big supporter of him but primarily for his environmental policies. He was the candidate I voted for in the primaries. However, I did not vote for him last night. So what changed my mind about him? There are a few reasons...and many of these reasons are why I have withdrawn my support from most major party candidates (Republican and Democrat). First reason...
Israel/AIPAC:
Obama pledged his allegiance to Israel and AIPAC (American Israel Public Affairs Committee). Even though I was raised jewish and have no hatred of jewish people or any religion for that matter, I do not agree with the AIPAC or our current policy with Israel. There is actually a huge jewish anti-AIPAC following. AIPAC is the second most powerful lobbyist group in the United States. The fact that a group that powerful exists soley for the well being of another country makes me outraged. This is a perfect example of how money and power can make policy decisions. Because of AIPAC's lobbyist efforts, we give an annual $4 billion military package to Israel. This is American taxpayers money being used to support the interest of a country that is not their own. This is one of the main reasons why muslim countries do not like this country.
The Bailout:
Obama's support for the bailout was the issue that officially made me withdraw my pledge to vote for him for president. The $800 bailout plan is a huge sum of money that we don't have. It's not like the government has that money. They have to print it or borrow it. The same thing for his support for the economic stimulus package (and a new one he's pushing for). We did not have the money so we had to either borrow or print more. But this helps the middle class you say? Yes it does but only temporarily and it causes more long term problems. Handing out money we don't have to taxpayers and banks is just like putting a bill on a credit card. Yes we can go buy whatever we want for a while but We will keep racking up the balance and eventually have to pay it back when we max it out. Our "max out" is enevitible.
Federal Reserve/Central Bank:
Obama has failed to be critical of the Federal Reserve and the Central Bank. The Federal Reserve is a group of private bankers who benifit from printing money. They print money out of thin air and loan it to banks ON INTEREST! Therefore, they make money out of printing money. The banks then loan us money ON INTEREST! How did the banks "earn" this money? Why do they deserve interest payments? This was one of the primary reasons for the Revolutionary War and our desire to break away from the Central Bank of England. Our current monetary policy results in a public that is eternally in debt and servitude to the banks. This is closely related to the recent bailout and economic stimulus packages when you think about it.
Also:
- Lack of media coverage of 3rd party candidates (you all saw the condradiction...Ron Paul signs everywhere and he won most of the straw polls but barely any media coverage of him)
- His reversal of his commitment to not receive public financing
Don't get me wrong. I like Obama. I am mesmorized when I hear him speak. He will be a great leader and bring people together better than Bush did or McCain would have. I knew either McCain or Obama would win and the 3rd parties had no chance, so I was very happy to hear Obama came out the victor. But when it comes down to it, he is not America's savior, we will still have the same monetary policy, we still have a powerful lobbyist group pushing us into war with Iran and keeping the anti-american flame lit. Even as I supported Obama from the beginning, I have said he is the best candidate for the "Planet" but not the best for America. An Obama presidency will not offer much "Change". The mess we are in has been a long time coming, way before Bush. I believe that until a major party candidate addresses the issues above, we will still be plagued by the same problems. This is why I withdrew my support for Obama and voted Nader (who I agreed with on all issues above). Keep a close eye on the candidates you voted in. Make sure they are fulfilling or trying to fulfill their promises. If they don't, don't vote them back in. Also, always be open to changing your mind on what you believe in. If you've had the same beliefs on the issues all of your life, you're most likely 99% wrong. Never blindly follow a political party and always vote for the candidate based on the issues you believe are most important to this countries well being.
Israel/AIPAC:
Obama pledged his allegiance to Israel and AIPAC (American Israel Public Affairs Committee). Even though I was raised jewish and have no hatred of jewish people or any religion for that matter, I do not agree with the AIPAC or our current policy with Israel. There is actually a huge jewish anti-AIPAC following. AIPAC is the second most powerful lobbyist group in the United States. The fact that a group that powerful exists soley for the well being of another country makes me outraged. This is a perfect example of how money and power can make policy decisions. Because of AIPAC's lobbyist efforts, we give an annual $4 billion military package to Israel. This is American taxpayers money being used to support the interest of a country that is not their own. This is one of the main reasons why muslim countries do not like this country.
The Bailout:
Obama's support for the bailout was the issue that officially made me withdraw my pledge to vote for him for president. The $800 bailout plan is a huge sum of money that we don't have. It's not like the government has that money. They have to print it or borrow it. The same thing for his support for the economic stimulus package (and a new one he's pushing for). We did not have the money so we had to either borrow or print more. But this helps the middle class you say? Yes it does but only temporarily and it causes more long term problems. Handing out money we don't have to taxpayers and banks is just like putting a bill on a credit card. Yes we can go buy whatever we want for a while but We will keep racking up the balance and eventually have to pay it back when we max it out. Our "max out" is enevitible.
Federal Reserve/Central Bank:
Obama has failed to be critical of the Federal Reserve and the Central Bank. The Federal Reserve is a group of private bankers who benifit from printing money. They print money out of thin air and loan it to banks ON INTEREST! Therefore, they make money out of printing money. The banks then loan us money ON INTEREST! How did the banks "earn" this money? Why do they deserve interest payments? This was one of the primary reasons for the Revolutionary War and our desire to break away from the Central Bank of England. Our current monetary policy results in a public that is eternally in debt and servitude to the banks. This is closely related to the recent bailout and economic stimulus packages when you think about it.
Also:
- Lack of media coverage of 3rd party candidates (you all saw the condradiction...Ron Paul signs everywhere and he won most of the straw polls but barely any media coverage of him)
- His reversal of his commitment to not receive public financing
Don't get me wrong. I like Obama. I am mesmorized when I hear him speak. He will be a great leader and bring people together better than Bush did or McCain would have. I knew either McCain or Obama would win and the 3rd parties had no chance, so I was very happy to hear Obama came out the victor. But when it comes down to it, he is not America's savior, we will still have the same monetary policy, we still have a powerful lobbyist group pushing us into war with Iran and keeping the anti-american flame lit. Even as I supported Obama from the beginning, I have said he is the best candidate for the "Planet" but not the best for America. An Obama presidency will not offer much "Change". The mess we are in has been a long time coming, way before Bush. I believe that until a major party candidate addresses the issues above, we will still be plagued by the same problems. This is why I withdrew my support for Obama and voted Nader (who I agreed with on all issues above). Keep a close eye on the candidates you voted in. Make sure they are fulfilling or trying to fulfill their promises. If they don't, don't vote them back in. Also, always be open to changing your mind on what you believe in. If you've had the same beliefs on the issues all of your life, you're most likely 99% wrong. Never blindly follow a political party and always vote for the candidate based on the issues you believe are most important to this countries well being.
Tuesday, September 30, 2008
saving $$$
With the expected economic downturn and credit crunch coming, I thought I'd post so money saving lifestyle changes that I've taken up over the past year.
1. Packing my lunch: I recently started packing my lunch again for work. So far its been a sandwich and some fruit/veggies. This also allows me to reduce my waste to only the paper towel that I wrap my sandwich in and use for a napkin.
2. Do things other than go to bars: When I go to bars, I don't drink a lot but when I get one or two drinks in me, I tend to buy drinks for friends. With decent beers being about $5 a bottle, this can get expensive. There are plenty of alternatives for things to do on the weekends. Anything outside is usually fun and free!
3. Cancel cable/watch tv online: You can watch most shows online now for free. Why spend $80 a month for something, when you can get it for free?
4. Join the library: Haven't done this yet but it hit me like a ton of bricks today. Why am I buying books when I can get them from a library? Less waste, less money. I know I won't be able to find some books in the library but mostly, I should be able to find something or borrow from someone.
5. Shut off unnecessary electronics/lights:
6. Drink water: I usually always get a glass at a restaurant and I drink from water fountains at work. I rarely buy bottled water (mostly because of the plastic waste). I have a water filter so I can drink free tap water at home. I do want to eventually get a reverse osmosis machine.
7. Get rid of land line: I use my cell phone for everything.
I estimate that doing these simple things has saved me about $400 a month. I'm working on being consistent with it. The past month, I've been awesome with it.
Really sounds like I've turned into "captain no fun" huh? Over the past couple years, I've slowly been cutting back on my expenses but it's still important to have fun and treat yourself and others every once and a while though.
1. Packing my lunch: I recently started packing my lunch again for work. So far its been a sandwich and some fruit/veggies. This also allows me to reduce my waste to only the paper towel that I wrap my sandwich in and use for a napkin.
2. Do things other than go to bars: When I go to bars, I don't drink a lot but when I get one or two drinks in me, I tend to buy drinks for friends. With decent beers being about $5 a bottle, this can get expensive. There are plenty of alternatives for things to do on the weekends. Anything outside is usually fun and free!
3. Cancel cable/watch tv online: You can watch most shows online now for free. Why spend $80 a month for something, when you can get it for free?
4. Join the library: Haven't done this yet but it hit me like a ton of bricks today. Why am I buying books when I can get them from a library? Less waste, less money. I know I won't be able to find some books in the library but mostly, I should be able to find something or borrow from someone.
5. Shut off unnecessary electronics/lights:
- I use my cell phone as an alarm clock
- turn off the power strip that my tv and stereo is plugged into when I'm not using it
- keep the lights off in rooms that I'm not in. It's also good to replace all lights with energy saving bulbs
- Don't leave computers on
6. Drink water: I usually always get a glass at a restaurant and I drink from water fountains at work. I rarely buy bottled water (mostly because of the plastic waste). I have a water filter so I can drink free tap water at home. I do want to eventually get a reverse osmosis machine.
7. Get rid of land line: I use my cell phone for everything.
I estimate that doing these simple things has saved me about $400 a month. I'm working on being consistent with it. The past month, I've been awesome with it.
Really sounds like I've turned into "captain no fun" huh? Over the past couple years, I've slowly been cutting back on my expenses but it's still important to have fun and treat yourself and others every once and a while though.
Monday, September 15, 2008
Your party has been hijacked
The collapse of two more major financial institutions today should serve as a reminder of what happens when we live beyond our means. We've become a country in debt. G. W. Bush enacted one of the largest tax cuts in US history and increased federal spending along with it (5 times greater than Bill Clinton - http://www.worldnetdaily.com/news/article.asp?ARTICLE_ID=51342 ) to finance an unjust preemptive war and increase spending to "Protect us from the terrorists". McCain will continue those tax cuts and I'm sure keep spending at the same levels with his support of many of Bush's programs (especially defense).
There are two formulas that work:
1. Higher taxes & a bigger government
2. Lower taxes & a smaller government
Lower taxes + bigger government = DEBT!! Horrible idea!
McCain's tax cuts will cost over $3 trillion. If he succeeds in his plan to reduce wasteful spending (getting rid of earmarks), he will cut a measly $20 billion. But McCain says the economy is "strong" so we should be fine!
Obama's tax increase (for the top 1% of earners) will generate an extra $181 billion. We will still be in debt but we'll be able to pay it off faster. Plus, hopefully he'll follow Bill Clinton's spending record. He's no messiah to the problem though.
Here's a recent article on the topic:
http://www.msnbc.msn.com/id/26689925
The current republican party has been hijacked by social conservatives and the religious right. It is no longer a party of fiscal conservatives and this is a clear example why religion and politics should not mix. Republican voters missed their chance by not nominating Ron Paul, a true fiscal conservative with a record and political philosophy to back it up. Read about his mission here http://www.campaignforliberty.com/mission/ People think he's nuts but he's predicted our current financial crisis.
So are the terrorists still our greatest threat? I think if anything they've gotten exactly what they wanted. To watch us slowly bleed a financial death in a war that can never be won. Stay informed, vote smart, we're going to need it.
There are two formulas that work:
1. Higher taxes & a bigger government
2. Lower taxes & a smaller government
Lower taxes + bigger government = DEBT!! Horrible idea!
McCain's tax cuts will cost over $3 trillion. If he succeeds in his plan to reduce wasteful spending (getting rid of earmarks), he will cut a measly $20 billion. But McCain says the economy is "strong" so we should be fine!
Obama's tax increase (for the top 1% of earners) will generate an extra $181 billion. We will still be in debt but we'll be able to pay it off faster. Plus, hopefully he'll follow Bill Clinton's spending record. He's no messiah to the problem though.
Here's a recent article on the topic:
http://www.msnbc.msn.com/id/26689925
The current republican party has been hijacked by social conservatives and the religious right. It is no longer a party of fiscal conservatives and this is a clear example why religion and politics should not mix. Republican voters missed their chance by not nominating Ron Paul, a true fiscal conservative with a record and political philosophy to back it up. Read about his mission here http://www.campaignforliberty.com/mission/ People think he's nuts but he's predicted our current financial crisis.
So are the terrorists still our greatest threat? I think if anything they've gotten exactly what they wanted. To watch us slowly bleed a financial death in a war that can never be won. Stay informed, vote smart, we're going to need it.
Friday, August 8, 2008
Inflate your tires
I've been trying to stay out of the political race. I already know who I'm going to vote for so there's no use in being further ill-informed by the joke that is mass media.
However, I heard about McCain bashing Obama for his statement that we could save fuel by properly inflating our tires. Yes, this wouldn't make much of a difference but its not the only fucking thing he suggested. It is a step towards a positive way of living and bashing statements like that is extremely ignorant and represents everything wrong in this country.
We need to build plug-in hybrids and use more wind/solar. Yes, offshore drilling will help our problem temporarily but we'll eventually be in the same boat again. We need the oil crisis. We need a shock to our system that makes everyone say, "Hey, why the fuck am I driving this huge gas guzzling SUV that I don't need when I could drive a smaller car for half the cost?" As soon as someone has that thought, they start thinking about the other wasteful things they do. I've been hearing a lot about plastic bag bans all over the world, more people are riding bikes, more people are exploring their local communities and buying local produce, more people are buying smaller homes that are closer to work. Do you think most people would care about this stuff if oil/gas was cheap again? The economy is the driving force in changing people's minds. I say make gas more expensive. Remove the oil subsidies (that we're paying in taxes!) and uncover the true cost that we're paying at the pump. Without oil subsidies, gas would be $10 a gallon. Take them away, give us our tax money back, then we can let the free market decide what kind of cars should be produced.
We've been going down the wrong path. The only thing we can do is head back (no matter how painful it is) and take the turn we should have taken in the beginning.
However, I heard about McCain bashing Obama for his statement that we could save fuel by properly inflating our tires. Yes, this wouldn't make much of a difference but its not the only fucking thing he suggested. It is a step towards a positive way of living and bashing statements like that is extremely ignorant and represents everything wrong in this country.
We need to build plug-in hybrids and use more wind/solar. Yes, offshore drilling will help our problem temporarily but we'll eventually be in the same boat again. We need the oil crisis. We need a shock to our system that makes everyone say, "Hey, why the fuck am I driving this huge gas guzzling SUV that I don't need when I could drive a smaller car for half the cost?" As soon as someone has that thought, they start thinking about the other wasteful things they do. I've been hearing a lot about plastic bag bans all over the world, more people are riding bikes, more people are exploring their local communities and buying local produce, more people are buying smaller homes that are closer to work. Do you think most people would care about this stuff if oil/gas was cheap again? The economy is the driving force in changing people's minds. I say make gas more expensive. Remove the oil subsidies (that we're paying in taxes!) and uncover the true cost that we're paying at the pump. Without oil subsidies, gas would be $10 a gallon. Take them away, give us our tax money back, then we can let the free market decide what kind of cars should be produced.
We've been going down the wrong path. The only thing we can do is head back (no matter how painful it is) and take the turn we should have taken in the beginning.
Subscribe to:
Posts (Atom)