Adding site Binding programmatically IIS 7.5 - c#

I am trying to add site binding programmatically. Here is my code:
using (ServerManager manager = ServerManager.OpenRemote("serverName"))
{
manager.Sites["siteName"].Bindings.Add(string.Format("*:{1}:{0}.localhost", clientCode, port), "http");
manager.CommitChanges();
}
I am getting the following Error. How do I get around this?
UnAuthorizedException: Retrieving the COM class factory for remote component with CLSID {} from machine failed due to the following error: 80070005

The account runs the code must be the administrator of the remote machine and also the DCOM related ports on the remote machine must be opened at firewall.

Related

Cannot recycle app pool remotely from IIS

As I have seen recommended, I am using the Microsoft.web.administration library, specifically the ServerManager.OpenRemote() and manager.ApplicationPools[poolName] code to try and recycle a remote application pool. My code is
var managerTwo = ServerManager.OpenRemote(serverTwo);
var testPoolTwo = managerTwo.ApplicationPools[testPoolName];
However I get the error
{"Retrieving the COM class factory for remote component with CLSID
{2B72133B-3F5B-4602-8952-803546CE3344} from machine wycvwwebd017
failed due to the following error: 80040154 wycvwwebd017."}
It seems this error means that it cannot find the class to load. I have checked in the registry on the remote machine and the clsid definitely exists. Any idea how to troubleshoot why COM cannot find the clsid?

Using C# to administer IIS

I would like to create an app that will deploy a website. Basically, I just want this app to copy the publish files to the webserver in a new folder, change the website to that folder, then recycle the app pool.
I found out that I should be able to do this with Microsoft.Web.Administration. I am having a problem with even the most basic task as I'm learning how to do this. here is my code in a windows form app to just play with this.
try
{
using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote("webservername"))
{
foreach (var site in sm.Sites)
{
MessageBox.Show(string.Format("{0}", site.Name));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
I'm simply trying to loop through the websites and display the names as my first try. The error I get is the following:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Web.Administration.Interop.IAppHostWritableAdminManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{FA7660F6-7B3F-4237-A8BF-ED0AD0DCBBD9}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).
at Microsoft.Web.Administration.ConfigurationManager.CreateAdminManager[TClass,TInterface](WebConfigurationMap webConfigMap, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap webConfigMap, String configPathToEdit, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap configMap, String configPathToEdit, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String rawConfigurationPath, String cacheKey, Boolean isAdminConfig)
at Microsoft.Web.Administration.ConfigurationManager.GetApplicationHostConfiguration()
at Microsoft.Web.Administration.ServerManager.GetApplicationHostConfiguration()
at Microsoft.Web.Administration.ServerManager.get_SitesSection()
at Microsoft.Web.Administration.ServerManager.get_Sites()
The line that errored is:
foreach (var site in sm.Sites)
I've tried this with both my local IIS8 express and a windows server 2008 IIS 7.5
What have I done wrong?
You may want to check the following points:
The Name of the server. If not sure try looking for in your IIS Management
The version of the .dll is the right for your version of IIS.
The .net framework version. Since it use System.Web it depends on full-version of the .net framework but not on the Client Profile subset.
The machine on which the code is executing needs to have the IIS Management Scripts and Tools Windows feature installed.
On a Windows client OS or on Windows Server 2008 R2 and earlier, you can install it via the following steps:
Open Control Panel > Programs > Turn Windows features on or off.
Drill down to Internet Information Services > Web Management Tools and check IIS Management Scripts and Tools.
You are trying to manage a remote server, so
The account runs the code must be the local administrator of that remote server.
The DCOM ports must be opened at firewall.

Error while access local machine outlook emails from web application

I have made a C#.net application to access all my folders and emails from my local machine outlook.
To make this application I have used COM object, my application is working fine with my local machine using link localhost:51514/mymail/list
Sample code
Microsoft.Office.Interop.Outlook.Application app = null;
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon("abc#mydomain.com","password", true, true);
Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
MapModel.InboxFolder = app.ActiveExplorer().Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
MapModel.CategoryList = SetCategoryList(MapModel.InboxFolder);
but when I put this application on server and then try to access my email I get error at runtime.
ERROR: Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following
error: 80080005 Server execution failed (Exception from HRESULT:
0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
The requirement of my project : where ever I open my application, it should access all emails from Microsoft outlook on that machine and list emails in my application.
seeking for some help, Thanks in advance.

C# PrincipalContext The network path was not found

I am trying to use PrincipalContext to check if a local user group exists on a remote computer.
I am having problems with PrincipalContext:
PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machine, null, ContextOptions.Negotiate)
It works in such scenarios:
local to local machine
local to virtual machine
domain machine to workgroup machine
However it doesn't work in opposite direction:
virtual machine to local host
workgroup machine to domain machine
I am getting these errors:
Unhandled Exception: System.IO.FileNotFoundException: The network path was not found.
Unhandled Exception: System.Runtime.InteropServices.COMException: The network path was not found.
The first exception is for virtual machine, second for workgroup machine.
All machines have user with the same name and password and the code was executed from that user.
How to solve this issue?
I found the answer. It looks that DirectoryServices doesn't work on remote Windows 7 or newer.
I guess when a computer is in a workgroup then it is local and we can connect and when it is in a domain then it is remote.
I followed steps described here:
System.IO.FileNotFoundException: The network path was not found. Exception while using DirectoryEntry object on windows 7
and here:
http://www.peppercrew.nl/index.php/2011/09/connect-to-remote-registry-fails-with-an-error-is-preventing-this-key-from-being-opened/
Enable File and Print sharing in the Firewall
Start the Remote Registry Service
Add remote user access to this registry entry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg
However I can't change services and registry settings on production servers. I found such way to get group:
var server = new DirectoryEntry(string.Format("WinNT://{0},Computer", machine));
DirectoryEntry group = server.Children.Cast<DirectoryEntry>().Where(
d => d.SchemaClassName.Equals("Group") && d.Name.Equals("Administrators")
).Single<DirectoryEntry>();

stonefield query web application cannot publish

i have problem publishing my web application on IIS. i'm using stonefield query tools which using SQProxyWrapper component.
When i publish the page on IIS i got this error:
Exception Details: System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {F83BAE78-C971-4083-B191-64AE6790104E} failed due to the following error: 80070005.
[UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {F83BAE78-C971-4083-B191-64AE6790104E} failed due to the following error: 80070005.]
SQProxyWrapper.SQProxy..ctor() +26
I believe that the component 'SQProxyWrapper' is blocked. The stonefield query use 2 dll SQProxyWrapper.dll and SFQWrapper.dll . is there anything that i need to do to this 2 dll before publishing the web application to IIS?
I tried to put the whole files and folders security to full access to everyone but no luck I still got the same error.

Categories

Resources