I have hosted 1 background worker on app-harbor for sending email. From last 3 to 4 days it is not working, I am getting error “Terminated with exitcode -2147467259”.
Below is script using in background worker:
static void Main(string[] args)
{
while (true)
{
//Worker_Process_For Send Email
EmailCls.SendEmail_ByMailGun("a#b.com", "a#b.com", "Testing Shailesh-live", "body-live");
}
}
public static IRestResponse SendEmail_MailGun(string from ,string to ,string subject,string body)
{
RestClient client = new RestClient();
client.BaseUrl = ConfigurationManager.AppSettings["mailgun_baseurl"].ToString();// "https//api.mailgun.net/v2";
client.Authenticator = new HttpBasicAuthenticator("api", ConfigurationManager.AppSettings["mailgun_key"].ToString());
var mailgun_domain = ConfigurationManager.AppSettings["mailgun_domain"].ToString();
RestRequest request = new RestRequest();
request.AddParameter(mailgun_domain,mailgun_domain, ParameterType.UrlSegment);
request.Resource = "{" + mailgun_domain + "}/messages";
request.AddParameter("from", from);
request.AddParameter("to", to);
request.AddParameter("subject", subject);
request.AddParameter("html", body);
request.Method = Method.POST;
return client.Execute(request);
}
The given script working fine in local machine but not from appharbor .
We recently added a new logging module which gives you real-time access to your background worker's STDOUT and STDERR.
You can start a log session by clicking the "Logging" link in the application's nav bar. That should give you more output to help identify and resolve this issue.
I just Changed application Start Object[ which was not set in past ]in Application property window and rebuild and hosted it on app-harbor and my application started working f9.
Related
Problem: I am unable to get content from an company internal webpage through using HttpClient or WebClient. I am able to get the content by accessing the URL directly, however.
Details: .NET Core 3.1 Razor Pages, IIS 10, Windows Authentication.
I have a website http://myintranet/Editor/Bib/4343 where a user can press a button to generate a static page. Behind the scenes, it attempts to read a stream from http://myintranet/Editor/NewBib/4343/true and create a static HTML page from it.
When clicking the button, the response is always IIS 10.0 Detailed Error - 401.1 - Unauthorized etc.
However when I access the webpage directly in the browser, it opens up just fine (note that if it is the first time accessing the website, I am prompted by the browser to enter my username and password. After that, the browser remembers these credentials).
Also note that when running it from localhost through Visual Studio, all works fine, the static page downloads properly too.
Here is my code:
Version 1:
public IActionResult OnPostGenerateStaticPage()
{
try
{
HttpClient client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true, PreAuthenticate = true });
HttpResponseMessage response = client.GetAsync(Url.PageLink().Replace("Bib", "NewBib") + "/true").Result;
var indexPageContents = response.Content.ReadAsStreamAsync().Result;
var cd = new System.Net.Mime.ContentDisposition
{
FileName = BibNumber + ".htm",
Inline = false,
};
Response.Headers.Add("Content-Disposition", cd.ToString());
return File(indexPageContents, "text/html");
}
catch (IOException)
{
return RedirectToPage("./Bib");
}
}
Version 2:
public IActionResult OnPostGenerateStaticPage()
{
try
{
WebClient client = new WebClient { UseDefaultCredentials = true };
string desiredUrl = Url.PageLink().Replace("Bib", "NewBib") + "/true";
var indexPageContents = client.OpenRead("desiredUrl");
var cd = new System.Net.Mime.ContentDisposition
{
FileName = BibNumber + ".htm",
Inline = false,
};
Response.Headers.Add("Content-Disposition", cd.ToString());
return File(indexPageContents, "text/html");
}
catch (IOException)
{
return RedirectToPage("./Bib");
}
}
Another thing, I have asked the web server admin to check that NTLM is above Negotiate for the authentication providers for this website and it is. Also, Anonymous and Basic Authentication are disabled and Windows Authentication is enabled.
Not sure where to go from here...
I have a Continuous WebJob published on my Azure Portal which performs some tasks.
I want to run this WebJob on call of WebAPI & WebAPI should not wait for the response, it should run WebJob in the background.
I have created one WebAPI & tried to call my WebJob but it is showing nothing.
WebAPI WebJobController.cs code:
public class WebJobController : ApiController
{
public void CallWebJob()
{
try
{
//App Service Publish Profile Credentials
string username = "userName"; //userName
string password = "userPWD"; //userPWD
string URL = "https://"+username+":"+password+"#reportjobprocess.scm.azurewebsites.net/api/continuouswebjobs/ContinuousReportServiceWebJob/run";
System.Net.WebRequest request = System.Net.WebRequest.Create(URL);
request.Method = "GET";
request.ContentLength = 0;
request.GetResponseAsync();
Console.WriteLine("OK"); //no response
}
catch (Exception ex)
{
Console.WriteLine("Something went wrong: " + ex.Message.ToString());
}
}
}
I'm totally new to WebJob & WebAPI. Please help.
You could use WebJobs API to start/stop WebJob.
Start:wiki
POST /api/continuouswebjobs/{job name}/start
Stop:wiki
POST /api/continuouswebjobs/{job name}/stop
If you want to invoke triggered webjob you could use this. It doesn't support stop triggered job.
If you still have other questions, please let me know.
Update : about credentials you could refer to this.
Azure has a fantastic ability to roll updates so that the entire system is not offline all at once. However, when Azure updates my web roles, the AppDomains are understandably recycled. Sometimes the ASP.NET startup code can take over a minute to finish initializing, and that's only once a user hits the new server.
Can I get Azure to start the AppDomain for the site and wait for it to come up before moving on to the next server? Perhaps using some magic in the OnStart method of WebRole?
See Azure Autoscale Restarts Running Instances which includes the following code:
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
string ip = null;
foreach (IPAddress ipaddress in ipEntry.AddressList)
{
if (ipaddress.AddressFamily.ToString() == "InterNetwork")
{
ip = ipaddress.ToString();
}
}
string urlToPing = "http://" + ip;
HttpWebRequest req = HttpWebRequest.Create(urlToPing) as HttpWebRequest;
WebResponse resp = req.GetResponse();
return base.OnStart();
}
}
I'm trying to connect to a CRM 2011 Online environment. I'm able to connect via a "Console Application", but when I'm trying to connect via an "ASP.net"-application with the same code, it doesn't work, it gives me the "Authentication Failure"-error ({"An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail."}).
Is there something special we need to do to make it work on an "ASP.net" environment. I tested out several solutions I found on the internet, but all gives me the same error.
A "code"-snippet of my simplified code:
private static ClientCredentials GetDeviceCredentials()
{
return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Authenticate using credentials of the logged in user;
string UserName = "*****"; //your Windows Live ID
string Password = "*****"; // your password
ClientCredentials Credentials = new ClientCredentials();
Credentials.UserName.UserName = UserName;
Credentials.UserName.Password = Password;
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("https://*****.crm4.dynamics.com/XRMServices/2011/Organization.svc"); //this URL could copy from Setting --> Developer Source
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
var theAccounts = orgContext.CreateQuery<Account>().Take(1).ToList();
Response.Write(theAccounts.First().Name);
}
}
I tried several things, like deleting the content of "LiveDeviceID"-folder an re-running the device registration tool. but is weird that it works in the "console application" but not on my "asp.net"-solution...
PS : I am able to generate the "context"-file via crmsvcutil.exe /url:https://org.crm4.dynamics.com/XRMServices/2011/Organization.svc /o:crm.cs /u:username /p:password /di:deviceUserName /dp:devicPWD
Is there any particular reason you have
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
You shouldn't need that line for windows live authentication.
Even with that the code seems valid so it is something to do with the Device Registration. I suggest rather than just call it directly like you have
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
{
You try something like the following because you only need to register once:
ClientCredentials deviceCredentials;
if ((CRMSettings.Default.DeviceID == String.Empty) || (CRMSettings.Default.DevicePassword == String.Empty))
{
deviceCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.RegisterDevice();
}
else
{
deviceCredentials = new ClientCredentials();
deviceCredentials.UserName.UserName = CRMSettings.Default.DeviceID;
deviceCredentials.UserName.Password = CRMSettings.Default.DevicePassword;
}
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, deviceCredentials))
{
I have had issues in the past where I get an "already registered" response from the RegisterDevice call.
I would also dump out the Device ID and Password so you can see if they are being set.
Ok, here's the problem i've been dealing with the whole day:
I'm building a web application forms using WCF Data Service and XPO as ORM Data Model in the server side which contains a method, and in the client side, i'm trying to add a line to a database from a web form after authenfitication.
The user can log in without problems with this code:
try
{
ctx = null;
ctx = new XpoContext(serviceRootUri);
ctx.Credentials = new NetworkCredential(UserName.Text, UserPass.Text);
var res = ctx.Users.FirstOrDefault();
FormsAuthentication.RedirectFromLoginPage(UserName.Text, Persist.Checked);
}
catch (SecurityException ex)
{
Msg.Text = "Erreur: " + ex.Message;
}
}
now i want to add a line to a database with this code:
Uri u = new Uri(string.Format(LogIn.ctx.BaseUri + "/CreateUser?name='{0}'&pass='{1}'",
New_UserName.Text, New_UserPass.Text), UriKind.RelativeOrAbsolute);
LogIn.ctx.Execute(u, "GET");
ServiceReference1.Users user = new ServiceReference1.Users();
user.Nom = New_UserName.Text;
user.Pass = New_UserPass.Text;
LogIn.ctx.AddToUsers(user);
LogIn.ctx.SaveChanges();
but after executing in the 1st two lines an exception occurs.
i'm declaring my context as static in the logIn page:
private static Uri serviceRootUri = new Uri("http://localhost:28748/WcfDataService1.svc/");
public static XpoContext ctx;
As u can see i call my context in the adduser web form with LogIn.ctx ( the same context in the log in page )
Thanks