Visual Studio 2022 with all updates and running on .Net Framework (not Core)
I would like to use Application Insights so when my app raises any relevant errors/events it is recorded to AppInsights.
I started with this tutorial https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net and created two different application along with having events being recorded which i can see in Azure App Insights.
When i view the data it has the same AppID for two applications i created. I cant find any document to suggest where i could change the appId or any other way to state the source of the event if from application one or application two.
After viewing the reports and documentation im not sure if i need to configure Azure App Insights differently or if i could change it at app level? I just want to be able to record any errors but also have a way to determine which application the error was raised from?
Edit
I have added the below class
public class ReportInitialise : ITelemetryInitializer
{
public void Initialise(ITelemetry telemetry)
{
telemetry.Context.Cloud.RoleName = "Test";
telemetry.Context.Cloud.RoleInstance = "TestInstance";
}
}
Edit 2
In the MvcApplication class i added the below to Application_Start
TelemetryConfiguration.Active.TelemetryInitializers.Add(new ReportInitialise );
which resolved the last part of the puzzle
When i view the data it has the same AppID for two applications i created.
That is correct. It is the ID of the Application Insights resource.
After viewing the reports and documentation im not sure if i need to configure Azure App Insights differently or if i could change it at app level? I just want to be able to record any errors but also have a way to determine which application the error was raised from?
Typically this is done by inspecting the cloud_RoleName property. In Web Apps afaik this is set to the web app name. You can override it using a telemetry initializer if you want.
Related
I have created a web application in .Net core(v5.0) and hosted it in Azure App Service. I have created a view and that allows me to add a new URL based on that create a new subdomain in the same service and publish code in that. This concept also uses in Jira software where our <projectname>.atlassian.com
Eg:
I have added dev in a text box then-new subdomain added like. dev.<myappservicename>.azurewebsites.net
In this case, all code copy and run this code properly.
Main Domain:
Base URL(Created URL): <myappservicename>.azurewebsites.net
Custom URL(Added from View): dev.<myappservicename>.azurewebsites.net
,
admin.<myappservicename>.azurewebsites.net
Technology Specification:
.Net Core(5.0)
C#
Azure App Service
If anyone has an idea then suggest thought.
It helps me a lot.
You can use restapi or .net sdk to create subdomain.
From your description, I see that there should be no need to redeploy your webapp, so if there is a business need, it is recommended to identify it through the program, what is the input url of the browser, to process your program.
Eg:
company1.<projec_tname>.azurewebsites.net
Get HttpRequest url to handle company1's bussiness.
company2.<projec_tname>.azurewebsites.net
Get HttpRequest url to handle company2's bussiness.
I'm setting up a new server with windows Azure VM for a asp.net mvc 5 application. I'm able to open every page of the application without a problem with an exception of one controller. i.e. whenever I try to open a page belong to a specific controller, it prompts me for user name & password as below.
I use the same application in a different Windows Server 2016 VM without any issues.
I don't see any errors of the application/IIS logs either. I don't have any https requirements in the application.
What may be causing this behaviour?
namespace App.Controllers
{
public class ReportsController : BaseController
{
private readonly IReportRepository reportRepository;
public ReportsController(): this(new ReportRepository()){
}
public ReportsController(IReportRepository reportRepository){
this.reportRepository = reportRepository;
}
public ViewResult Action()
{
return View(reportRepository.All);
}
}
}
namespace App.Controllers
{
[Authorize]
public class BaseController : Controller
{
}
}
UPDATE: I renamed the ReportsController to AppReportsController and the issue disappeared.
i.e. I get the above prompt when I try to access
http://domain/Reports/Action
but not for
http://domain/AppReports/Action
Could you please someone explain to me what's going on here? Does it mean that "Reports" is reserved by the framework or something?
This is an authentication issue. In my case, it solved by below steps:
1- Go to IIS manager, in the left pane, expand the server root and select your web application from Sites node.
2- In the Home screen, go to IIS section and select Authentication.
3- Enable Anonymous Authentication.
4- Then, select Edit and set Edit Anonymous Authentication Credentials to Application pool identity.
I know this was an old post however I stumble on this one because I encountered the same error as the OP does.
I have solved this one in case there's someone encounters the same as this.
but the solution may vary depends if we have the same applications installed.
check if the web server / server has an installation of sql server.
check if there is reporting services installed.
remove / uninstall the reporting services from the application control panel
follow this link if you don't know how to remove the report service How to remove Report Service
Please check again if you still encounter the same error. Cheers!
The browser will tell you your connection to the site is not private if you don't use transport layer security (i.e. HTTPS) in your web application, and you are being asked to enter data - in this case your credentials. Doing this is dangerous because that data can easily be sniffed by a malicious person.
There is no reason in today's world to not have a secure site, I strongly recommend you get a certificate (they are free and super easy!)
Just don't use "Reports" use "Report" instead. Controller name ReportController not ReportsController. It'll be alright. I've faced the problem and this is the solution I've got.
I'm using a TelemetryClient class to send different types of telemetry (from my WPF app), but I have a problem with MetricTelemetry... all other types of telemetry work fine, but my MetricTelemetry custom data doesn't appear in the Metric Browser - Custom...
I call for example telemetryClient.TrackMetric("MyMetric", 1), then go to the Azure portal, but custom metrics still contains only "Azure Diag issues" field
I had the same issue. For me, it helped doing two things:
Call Flush() on the telemtryClient after sending the message
Logged in to Azure using inccognito mode, to away cached items
Dominik, does the problem still exist? Sometimes you might see a ~5-10 mins delay in time between you run the code to track metric and the metric shows up in the portal.
I have a project based on the Chris Hammond, Christoc, module template. I have a ton of code that I use to access data an external database. In my repositories I change the database from the default to whichever I need for that particular object. I do so with code that looks like this:
using (IDataContext ctx = DataContext.Instance(MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY))
{
var rep = ctx.GetRepository<Product>();
products = rep.Get().ToList();
}
The default database is switched in the call to .Instance(). The repositories are used by my custom DNN modules. The repository is part of the solution that contains multiple custom modules. When I compile and install using the Extensions part of DNN, everything works well. In the code above, MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY is found in a file MyModuleSettingsBase.cs file of my module solution. It is set to a simple string like "ProductDatabase". In the solution for the base DNN install (not the module solution), within the web.config file, there is a value in <connectionStrings> with name="ProductDatabase" which contains the actual connection string. This all links up fine on the DNN website.
Now I am writing a console application that does some monitoring of the site. I want to access the database to check values in the product table. I would like to reuse all of the repository code I have written. In an attempt to do so, I added a reference to the MyModules.dll file so I would only have one copy of the base code. This works to give me access to all the objects and the associated repositories but when I attempt to query data it fails. When debugging I can see that it fails on the line:
using (IDataContext ctx = DataContext.Instance(MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY))
When viewed in a debugger, the string value MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY is correctly set to "ProductDatabase" but the code is unable to link this with the actual connection string. I don't know where it would be checking for the connections string when running from my console application. I attempted to put a <connectionStrings> section into my App.config file but this didn't do the trick.
Is it possible to have MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY map to the connection string in an external application which references the DLL?
If so, where can I set the value of my connection string so it matches up to the key value stored in MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY?
I was faced similar problem 3 months ago, at that time I want to use DNN core libraries in my console application but I was failed.
I placed my queries in DNN official forum website and I got a valid response from Wes Tatters (DNN MVP).
Here is the post link: Reference URL
As your requirement of monitoring, I suggest you to create DNN Schedule Application. You can schedule it within DNN (Host->AdvancedSettings->Schedule), even good point is that you can use your repositories (DNN Libraries) in that schedule application.
I hope it solved your problem. Let me know if you have any questions.
I have a general c# Tools DLL which is being used both in a console library and also in a web application. Depending on whether the DLL is being used in a web application or in the console I need certain methods to execute differently.
Is there a way to determine if we are in a web context or console application context from within a given method? I realize that I could use a config file to achieve this, but in my situation it would be preferable if I could accomplish this in the method.
You should parameterize this information and pass that to the class/methods you want to use.
You can't determine (in a reliable way) if one application is a web application or console application because they are not mutally exclusive. A console application can behave as a web application too, take OWIN as an example.
If you insist to do it automatically you define and use an Attribute in the executable assembly:
[AttributeUsage(AttributeTargets.Assembly)]
public class AppModelAttribute : Attribute {
public ModelType Model {get;private set} // This one can be an enum type with values Web, Console
public AppModel(ModelType type)
{
this.Model = type;
}
}
Add this assembly in your executing assembly:
[assembly: AppModelAttribute(ModelType.Web)]
Then you can query this attribute and determine if the executing assembly is Web or Console:
var attributes = assembly
.GetCustomAttributes(typeof(AppModelAttribute), false)
.Cast<AppModelAttribute>();
Above query is taken from here.
EDIT: I mean a console application can start as a web server and behave as a regular web application, for example HttpServer class can be used in any kind of application and it lets you answer http messages (GET, POST etc). OWIN is an example of a console application behaving as a web application.
You can however define a web application as an application running on IIS in your context. Then you need to somehow analyze the process and see if it actually is hosted by IIS, but that would be certainly an overkill.