Errors appear after connecting to Exchange Web Services (EWS) in C# - c#

First of all, sorry for my poor english...
Let's see if I can summarize the problem, it is quite strange:
Before we start... I have 2 users inside my company's domain.
User1 --> Has a proxy configured
User2 --> NO proxy configured
You are only able to navigate if you have the company's proxy configured, otherwise it won't load any webpage
1 - I log on into my computer using User1 domain credentials
2 - First, I open Internet Explorer, and I can navegate to any webpage, everything works fine. (I keep the window opened)
3 - I have a C# aplication running on my computer, which connects to EWS and logs into the mailbox of User2. The code looks like this:
ExchangeService serviceInstance = null;
serviceInstance = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
serviceInstance.DateTimePrecision = DateTimePrecision.Milliseconds;
serviceInstance.Credentials = new WebCredentials(user, pass, domain);
serviceInstance.AutodiscoverUrl(mailbox);
After I connect to the mailbox, I loop the messages for different purposes, everything works fine, and I close the aplication.
4 - I open the same IE window from step 1 (I didn't close it) and I try to load any other page, for example, https://google.com the page doesn't load and it shows me a certificate error:
Certificate error
If I click on 'Continue to this website', a firewall error appears.
Firewall error
5 - If I close the IE window and open a new window, something, I don't know what, seems to restart, and I can navigate again to any webpage.
I have explained this problem with the Internet Explorer case, but that's just to make it more visual. I have another aplications on this computer which need to make http calls, connect to webservices... And they sometimes fail because of this.
Does anybody know what is happening? How can I solve this?
Any help is appreciated!

You could try defining the proxy in your code eg
// set up the proxy
WebProxy proxy = new WebProxy("valid-proxy", 8080);
proxy.Credentials = new
NetworkCredential("valid-user","valid-password","valid-domain");
service.WebProxy = proxy;

Related

One of the URLs on my web site (on Azure VM Windows 2012 server) has started getting “This page can't be displayed” when browsed on my , .NET web app

One of the URL's to my website no longer works and gives me this error: "This page can't be displayed. Make sure the web address http://my_web's_previous_IP is correct"
(This is strange because "my_web's_previous_IP" was my web's IP up until January, when IP was changed after I restarted Azure .)
I have 4 different URL's registered to reach web. All 4 used to work ok, but now one, the primary one, doesn't anymore.
1. my_long_URL.org FAILS (and this is the primary web URL on my Azure IIS)
2. www.my_long_URL.org FAILS
3. my_long_URL.com works tiny_URL.org works
4. tiny_URL.com works www..org & com works
Web is VB.NET web app on Azure VM Windows 2012 server.
Registrar for my_long_URL.org says it's generating correct IP ok.
All email to my web by name#my_long_URL.org works ok and gets to my Azure email processing app ok.
I've done obvious things like restart the VM.
Azure > Windows > IIS Manager > Connections > Start Page > () > Application Pools > Sites > my_long_URL.org > each Site Binding is type http, port 80, and has same Azure internal IP Address.
... > Site Bindings > command to Browse: browses web for all ok, except I get the error browsing: www.my_long_URL.org
Site Bindings > command to Browse: my_long_URL.org WORKS OK(!)
I get exact same browse outcome when I click Actions column on the right-hand side > the URL's below Actions > Browse Website.
I have tried removing and re-adding bindings for both www.my_long_URL.org and my_long_URL.org but still get problem.
Azure > Windows > IIS Manager > Connections > Start Page > () > Application Pools > Sites > my_long_URL.org > right click it > Manage Web.. > Browse: works ok
According to your description, I have created a test VM and host a web site on it. It works well.
I guess you may not set the right Network security group inbound security rules.
So you will face this error.
So I suggest you could follow below steps to check you have already add the new Network security group inbound security rules.
Select networking in the VM
2.Click add the inbound port role.
3.Add your IIS website port in it.
Then it will work well. More details about how to host web site in IIS, you could refer to this video.
After a few weeks, it just started working again!
Explanation:
A. I prayed to God, so maybe it was a miracle. :-)
B. The bad URL was the only one hosted by Aabaco. The other URLs were hosted by Network Solutions. The www error message always showed the old IP from back in January. However, the URL worked with email. So maybe Aabaco had a fault using the new IP with http traffic.
But, it works now! Praise God!

The LDAP Server is Unavailable using PrincipalContext and ADLDS

We are making use of ADLDS for our user management and authentication. We can successfully query the instance without problems. However, trying to perform an operation such as SetPassword will fail or even trying to create a new user if a password is not set, it fails. I can successfully update a user as long as its not password I'm trying to update. I've been reading a lot of different articles relating to this but not finding a resolution. Posting to see if I can get some fresh perspective on this issue, thanks for any input.
EXAMPLE
ContextType ctxType = ContextType.ApplicationDirectory;
string server = "myadldsserver.com";
string usersCN = "CN=Users,..."; // container where users reside
ContextOptions ctxOpts = ContextOptions.SimpleBind;
string uname = "myuser";
string pswrd = "mypass";
using(var ctx = new PrincipalContext(ctxType, server, usersCN, ctxOpts, uname, pswrd)
using(var newUser = new UserPrincipal(ctx)) {
newUser.Name = "newusername";
newUser.Enabled = true;
newUser.UserPrincipalName = "newusername";
newUser.Save();
newUser.SetPassword("newuserpassword");
}
ERROR 1
The first problem I encounter if I try to create a new UserPrincipal and call Save without having set the password like in Example above I get the exception A constraint violation occurred. with an InnerException extend message of 0000052D: AtrErr: DSID-033807D7, #1:0: 0000052D: DSID-033807D7, problem 1005 (CONSTRAINT_ATT_TYPE), data 2246, Att 9005a (unicodePwd)
Because of this error I tried moving the SetPassword before calling Save along with other approaches I found online such as getting the DirectoryEntry from the UserPrincipal and trying to call SetPassword but got a different error.
ERROR 2
Calling SetPassword before calling UserPrincipal.Save, when save is called, results in the error The directory property cannot be found in the cache.
Note that the same error will occur if I trying calling ResetPassword or getting a DirectoryEntry and calling Invoke("SetPassword"... as well
ERROR 3
From my research most seem to indicate this could have to do with needing to access AD LDS using a Secure connection. So, I changed my server to include the port of 636 string server = "myadldsserver.com:636" and I changed the ContextOptions to be ContextOptions.SimpleBind | ContextOptions.SecureSocketLayer.
Making these changes when the PrincipalContext is being constructed I get the following exception The server could not be contacted. with an inner exception of The LDAP server is unavailable., HResult is -2146233087
JAVA and LDP
To add some background to this, we do have similar code written in an older Java application. We are trying to port some of this logic over to .NET side in C#. The code in Java makes use of a Java keystore that contains the certificate that was generated on the AD LDS server. The Java application of course has no issues using the SSL port. We know the server seems to be configured correctly, it's just an issue of how to access it from .NET side.
Is there an equivalent on the .NET side such as the keystore in Java? We know that an SSL connection can be made to server. We have verified this using LDP as well.
GOALS
Be able to create a new user and set their password during creation
Be able to ResetPassword or ChangePassword for a user
Connect to our AD LDS instance from .NET securely
Have you tried using Microsoft Management Console to import the certificate?
Two ways to install the certificate
Either
Open a cmd.exe console and type "MMC"
File > Add/Remove Snap-In...
Select Certificates, click Add
Choose Computer Account and Local Computer when prompted, then OK...
Certificates should now be showing under Console Root
Certificates > Trusted Root Certification Authorities > Certificates > (right-click) > All Tasks > Import Certificate...
Find the certificate you want to import, click Next and choose defaults (Trusted Root Certification Authorities should already be
selected)
Click Next, Finish
(or)
Simply double-click on the .cer file for the certificate in Windows
Explorer, click Install Certificate... > Next > select the option to
"Place all certificates in following store" > Browse... > Select
Trusted Root Certification Authorities. Continue with next until done.
At this point your certificate is installed, and you should be able to communicate securely with your ADLDS server.

Custom TFS server plugin throws exception TF30063

I've been writing a custom TFS 2013 server plugin for my company that automatically creates tasks whenever a new bug or product backlog item is created. While debugging I can see it detecting the new work item, but when it tries connect to the TfsTeamProjectCollection it throws TF30063 exception saying I'm not allowed to access the server. What baffles me is, in an attempt to see if the code after that worked, I made a simple client-side form application with the exact same code to connect to the server and it worked flawlessly.
The code I'm using to connect with is:
string tfsUri = string.Empty;
tfsUri = #"http://companytfsserver:8080/tfs/defaultcollection";
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsUri));
tfs.EnsureAuthenticated();
I've also tried manually setting the credentials, but no luck. Also, if it helps, I used this as my guide: http://geekswithblogs.net/BobHardister/archive/2012/10/08/automatically-create-bug-resolution-task-using-the-tfs-2010-api.aspx
I read through a ton of documentation of people getting the same exception, but none of what I found seemed relevant to this particular situation, so any help would be greatly appreciated!
*Update: After more digging and testing, it's possible it may have something to do with our application tier. I'll have to wait for the IT guy that's familiar with that particular system to get back from a conference (Monday, I think), but I'll update once I find out for sure.
**Update: I finally figured it out and I can't believe how simple it was. It turns out the URI that's used to connect via client app does not work when it's used in an app tier server plugin. Instead, it has to be localhost:8080/tfs/defaultcollection. Makes perfect sense to me now, but it never even crossed my mind before.
Just as jessehouwing says, since you are using collection uri "http://companytfsserver:8080/tfs/defaultcollection" You must have permissions on the Prioject(collection) with your account and TFS service account.
// Connect to TFS Work Item Store
ICredentials networkCredential = new NetworkCredential(tfsUsername, tfsPassword, domain);
Uri tfsUri = new Uri(#"http://my-server:8080/tfs/DefaultCollection");
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(tfsUri, networkCredential);
WorkItemStore witStore = new WorkItemStore(tfs);

A registration already exists for URI after stop/start

I am currently working on an application where I am creating a ServiceHost, then getting rid of it, then recreating it later. The problem is that once I get rid of the service host when I try to recreate it I get the exception "A registration already exists for URI after stop/start." The weird thing is I have three separate hosts and one works and two don't. I assume something is not being disposed of properly but I'm not sure why.
I am creating the hosts like this
host = new ServiceHost(typeof(MyService));
host.Open();
Then getting rid of them like so
if (host != null)
{
host.Close();
host = null;
}
I have also tried abort instead of close without any luck.
Though I am not sure about the exact issue, I can give you a little thought on it and some workaround.
If you are working in Windows 7, any URL you create as part of your hosting has to get registered. Netsh command usually helps us register and unregister the URLs.
For both registering and unregistering URIs you need to have admin permission.
You may try the following.
If you are running your exe, try running it in Administrator mode. (Right click and select admin mode).
If you are trying out with visual studio, try to restart the visual studio in admin mode and run the app.
Try to unregister the URI and try again using Netsh.
http://saravananarumugam.wordpress.com/2011/03/01/http-could-not-register-url/
may help you.

System.Deployment.Application ApplicationDeployment with a Proxy in C#

I am using ClickOnce for a C# Windows Forms application, and want to allow people to update the software by clicking an Update button, which will check the server online to see if there are any updates. I am using the following method (not exact, but same principle):
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
ad.CheckForUpdateProgressChanged += new DeploymentProgressChangedEventHandler(ad_CheckForUpdateProgressChanged);
ad.CheckForUpdateCompleted += new CheckForUpdateCompletedEventHandler(ad_CheckForUpdateCompleted);
ad.CheckForUpdateAsync();
This all works fine, the problem is trying to run this code from behind a proxy. A 407 error: Proxy Authentication required occurs. I can't find anywhere in the ApplicationDeployment class to enter proxy settings, even though ad.CheckForUpdateAsync() simply does a webrequest to the server (I assume). Any ideas?
Thanks!

Categories

Resources