Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) - asp.net

Code snippet :
public static void SendEmail(string _ToEmail, string _Subject, string _EmailBody)
{
oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem email = (Microsoft.Office.Interop.Outlook.MailItem)(oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem));
email.Recipients.Add(_ToEmail);
email.Subject = _Subject;
email.Body = _EmailBody;
((Microsoft.Office.Interop.Outlook.MailItem)email).Send();
}
this method works well when i tested it in another project(located in file system) but when tried to test it from IIS (virtual site);It throw this exception in line : email.Recipients.Add(_ToEmail);
any help will be appreciated
P.S. the ASPNET account has the administrator permission
thanks in advance.

Make sure that the reference is set in your web.config

Related

Delete file security issue in asp.net

I use fileUpload control and i can save the image but when i try to delete it gives a security error like this :
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
it works in my localhost but not in web.
I tried to add many kind of stuff to web config file but it didnt work i dont know why.
Why i can save file but cant delete. It might be about System.Security.Permissions.FileIOPermission maybe... here is my code :
protected void btnDelete_Click(object sender, EventArgs e)
{
try
{
if (!String.IsNullOrEmpty(imgLogo.ImageUrl))
{
int index = imgLogo.ImageUrl.LastIndexOf('.');
string fileExt = imgLogo.ImageUrl.Substring(index);
string defPath = Business.DefinitionsData.getDefaultLogoPath();
string entId = ((xOrgProject.DataAccess.EnterpriseUserTable)Session["Enterprise"]).EnterpriseUserId.ToString();
string FullPath = Server.MapPath(defPath) + entId + fileExt;
FileInfo file = new FileInfo(FullPath);
if (file.Exists)
{
file.GetAccessControl();
file.Delete();
Business.DefinitionsData.UpdateEntLogoPath(int.Parse(entId), null);
imgLogo.ImageUrl = null;
imgLogo.Visible = false;
btnDelete.Visible = false;
btnUpload.Visible = true;
Fu1.Enabled = true;
StatusLabel.Text = "Kaldırıldı.";
}
}
}
catch (Exception ex)
{ StatusLabel.Text = ex.Message; }
}
As it runs fine locally the issue is most likely due to the configuration on the web server. Or in my experience this has often been the case.
Have you tried modifying the trust level in the machine.config file on the web server?
Also what authentication are you using on the web server?
Running it locaally you will have access to your machine but if you are using impersonation on the web server that anonymous account ID may not have the relevant server permissions to delete files which will throw a security exception.
thank you for your answer, i got my solution. I have wrote this code in uploading button click event then its solved. I wasnt disposing before. but now its good. thanks again.
System.Drawing.Image img = System.Drawing.Image.FromFile(save);
img.Dispose();

Asp.net search Active Directory from IIS

Recently I moved my ASP.NET application from an old server running IIS5 to a new server running IIS7.5.
The application gives me an error:
The (&(objectCategory=person)(sAMAccountName=)) search filter is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The (&(objectCategory=person)(sAMAccountName=)) search filter is invalid.
The function that searches AD is:
public static string Get_AD_User_Email(string username)
{
try
{
DirectorySearcher searcher = new DirectorySearcher("(&(objectCategory=person)(sAMAccountName=" + username + "))");
SearchResult result = searcher.FindOne();
if (result != null)
{
DirectoryEntry employee = result.GetDirectoryEntry();
if (employee.Properties["mail"] != null)
{
return employee.Properties["mail"].Value.ToString();
}
else return "NULL";
}
else throw new Exception("ERROR: Problem searching active directory for users.");
}
catch (Exception ex) { throw ex; }
}
The weird thing is that on debug in Visual Studio the website is running, only from IIS it's crashes.
Can someone help me?
The trouble is just that your function Get_AD_User_Email(string username) is called with an empty value for username.
Since:
DirectorySearcher searcher = new DirectorySearcher("(&(objectCategory=person)(sAMAccountName=" + username + "))");
Is returning the exception:
The (&(objectCategory=person)(sAMAccountName=)) search filter is
invalid.
You are passing an empty string to Get_AD_User_Email.
How are you retrieving "username"?
You changed IIS servers, now no username is being passed in by the calling method (as several other answers point out).
I would verify that you have anonymous access disabled on that website in IIS. It's common to find both Windows authentication and anonymous access enabled. When this happens anonymous is preferred and you won't get the username.
Check the value of HttpContext.Current.User. I usually use code like the one below to verify windows authentication:
WindowsIdentity id = (WindowsIdentity)HttpContext.Current.User.Identity;
string username = id.Name;
Try:
objectClass=user
Instead of:
objectCategory=person

Magnolia Mail Module Doesn't Work

Im trying to send an email using Mail Module in Magnolia CMS 4.5.4. The code I have so far is:
protected void sendEmail(CommentDTO comment){
if(comment!=null){
try{
MgnlMailFactory mailFactory = MailModule.getInstance().getFactory();
if(mailFactory!=null){
Map<String, Object> params = new HashMap<String, Object>();
MgnlEmail mail = mailFactory.getEmailFromTemplate("MyTemplate", params);
mail.setToList("whoever#whatever.co.uk");
mail.setBody("HELLO");
mail.setFrom("whoever#whatever.co.uk");
if(mail!=null){
MgnlMailHandler mmh = mailFactory.getEmailHandler();
if(mmh!=null){
mmh.prepareAndSendMail(mail);
}
}
}
}catch(Exception e){
}
}
}
The log I get is:
2013-02-22 16:52:30,357 INFO fo.magnolia.module.mail.handlers.SimpleMailHandler: Mail has been sent to: [2013-02-22 16:52:30,357 INFO fo.magnolia.module.mail.handlers.SimpleMailHandler: Mail has been sent to: [whoever#whatever.co.uk]
But the email never come...
Before this trace I get :
2013-02-22 16:52:24,212 WARN info.magnolia.cms.util.DeprecationUtil : A deprecated class or method was used: Use IoC!. Check the following trace: info.magnolia.module.mail.MailModule.getInstance(MailModule.java:80), info.magnolia.module.mail.MgnlMailFactory.getEmailHandler(MgnlMailFactory.java:69), the full stracktrace will be logged in debug mode in the info.magnolia.cms.util.DeprecationUtil category.
Eclipse marks the method MailModule.getInstance() as deprecated but I have no idea what I must to put instead.
Somebody can help me?
Thanks!
As there are no thrown Exceptions, I guess you wrongly configured your SMTP server or not at all. How to do this can be read here: http://documentation.magnolia-cms.com/modules/mail.html#ConfiguringSMTP
Also, assure that:
Your mail didn't land in any spam filter (maybe outside your mailbox)
There are no blocking firewalls (e.g. when running on localhost)
Ok, I finally solve it with this code:
protected void sendEmail(CommentDTO comment){
if(comment!=null){
try{
MgnlMailFactory mailFactory = MailModule.getInstance().getFactory();
if(mailFactory!=null){
Map<String, Object> params = new HashMap<String, Object>();
params.put("articleName", comment.getArticleName());
params.put("id", comment.getId() );
params.put("commentText", comment.getComment());
params.put("author", comment.getName());
MgnlEmail mail = mailFactory.getEmailFromTemplate("myTemplate", params);
mail.setBodyFromResourceFile();
if(mail!=null){
MgnlMailHandler mmh = mailFactory.getEmailHandler();
if(mmh!=null){
mmh.prepareAndSendMail(mail);
}
}
}
}catch(Exception e){
log.error("Error sending email: " +e.getMessage());
}
}
}
I think what it make it works was this line:
mail.setBodyFromResourceFile();
And, of course, a good configuration of the SMTP server.

error reading oulook using MAPI in ASP.NET

I use VS2010, C#, ASP.NET to read outlook email. I've setup outlook express 6 with my gmail (IMAP), I get a strange exception at the first line, where my COM object is being created, here is my code:
Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.PostItem item = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
try
{
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon("gmail_id", "gmail_pass", false, true);
inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
subFolder = inboxFolder.Folders["MySubFolderName"]; //folder.Folders[1]; also works
Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());
for (int i = 1; i <= subFolder.Items.Count; i++)
{
item = (Microsoft.Office.Interop.Outlook.PostItem)subFolder.Items[i];
Console.WriteLine("Item: {0}", i.ToString());
Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());
Console.WriteLine("Categories: {0}", item.Categories);
Console.WriteLine("Body: {0}", item.Body);
Console.WriteLine("HTMLBody: {0}", item.HTMLBody);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
}
finally
{
ns = null;
app = null;
inboxFolder = null;
}
it is my exception:
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
this exception is create at the first line:
app = new Microsoft.Office.Interop.Outlook.Application();
I've used Microsoft.Office.Interop.Outlook.dll file as my interop reference, what is going wrong here? I can read my Gmail inbox in outlook express 6, but I have no luck in my ASP.NET web app
Try configuring the appropriate COM Activation permissions for Office apps to run under ASP.NET.
Firstly, you should not ever use any Office app (Outlook included) in a service (such as IIS). No exceptions, it is simply not supported.
Secondly, if you are using the Outlook Object Model (not in a service), you need to have Outlook (the real one) intalled. OE has nothing in common witt Outlook 2010/2007/2003/etc., except for the word "Outlook" in the name.

Report Server Credentials and Missing End Point Exception

Actually what I needed was a step by step guide but anyway..
I have to show some rdl reports in a web-site using the ASP.NET report vievew and do all the necessary configurations for the Reporting Services. The users of the page should not deal with ANY authorization.
Here is my code for the report viewer:
rprtView.ServerReport.ReportServerCredentials = new ReportServerCredentials();
rprtView.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
rprtView.ServerReport.ReportServerUrl = new Uri(#"http://mydomain/reports");
rprtView.ServerReport.ReportPath = #"/MyReports/PurchaseOrder";
rprtView.ShowParameterPrompts = false;
ReportParameter[] parameters = new ReportParameter[1];
parameters[0] = new ReportParameter();
parameters[0].Name = "OrderNumber";
parameters[0].Values.Add(orderNumber);
rprtView.ServerReport.SetParameters(parameters);
rprtView.ServerReport.Refresh();
Here is my overload for IReportServerCredentials
public class ReportServerCredentials : IReportServerCredentials
{
public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
{
authCookie = null;
userName = password = authority = null;
return false;
}
public WindowsIdentity ImpersonationUser
{
get { return null; }
}
public ICredentials NetworkCredentials
{
get { return new NetworkCredential("myUserName", "myPassword"); }
}
}
I am able to login to "http://mydomain/reports", the default web site of the SSRS, using "myUserName" and "myPassword" (I am not sure if this is related). Still I am getting MissingEndPoint exception at SetParameters() method above. It says:
"The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version."
I am also responsible for configuring the Reporting Services for the necessary configuration for this scenario and I have heard that this issue is related to the config files in SSRS but I have no idea what to write in them. Any help is much appreciated!
The string provided for rprtView.ServerReport.ReportServerUrl should be for the Report Server service, not the Report Manager application.
Change this:
rprtView.ServerReport.ReportServerUrl = new Uri(#"http://mydomain/reports");
to this:
rprtView.ServerReport.ReportServerUrl = new Uri(#"http://mydomain/reportserver");
This page has some high-level info on the Report Manager interface, Report Server web service, and how they relate.

Resources