Base solution for your next web application

Activities of "michael.pear"

I wasn't able to find a folder ASP.NET in %AppData%, however, searching for other information on certificates for localhost, I finally found the problem. It appears that a certificate for "localhost" on my development system (virtual machine) had expired (4/3/24). A symptom that this had occurred was a warning message in the MIcrosoft Edge browser that my https//localhost: connection was not private when I started IIExpress from Visual Studio. The expiration date was 5 yrs after I initially setup my development environment for ASPNET Zero.

I was able to get things working with the following steps:

  1. Using "certmgr", delete the expired certificate for localhost from "Personal/Certificates".
  2. "Repair" IIExpress to generate a new certificate for localhost. (See https://stackoverflow.com/questions/20036984/how-do-i-restore-a-missing-iis-express-ssl-certificate)
  3. Delete the applicationhost.config file in the .vs folder of your project directory, and do a Clean/Build to restore it. Browser should now come up with no err when you start the debugger (see https://stackoverflow.com/questions/37352603/localhost-refused-to-connect-error-in-visual-studio).

Now, when I run nswag, everything generates normally.

So long term users, who may not have replaced their development systems or virtual machines and just updated them, you may run into your original development certificate expiring!

Yes, that works. Thank you.

For others that may run into this, this is the placeholder in WebUrlServiceBase.TenancyNamePlaceHolder.

Response from AZ Support's review of my TrainingManagerImporter class found that I had inadvertently included an [AbpAuthorize] attribute on the class, which was the source of the problem. Removing that, and the job now runs. Goes to show how it is easy to be blind to the obvious when reviewing your own code.

In this process, I also refactored to make sure that no ApplicationServices (which require authorized users) were iinjected, so I switched to using domain services for the database functions. I saw that this could be a problem in other postings, such as StackOverflow https://stackoverflow.com/questions/52250802/background-job-fails-with-current-user-did-not-login-to-the-application

I sent the log file (with exception) and the source code to [email protected], rather than post in full here. Note I can't get any more detailed stacktrace than provided above. I can't catch the exception, as it appears to be happening in the BackgroundJob processing. The job is added to the AbpBackgroundJobs, and the exception appears to occur when the system tries to start the job, before my user code (in TrainingManagerImporter) is reached.

I found a solution for finding and using the tenant name in my helper class.

  1. Kept the helper class general by adding a string property that allows changing the container name to include the tenant name.
  2. To resolve the tenant name from either a current session or current unit of work, introduced a static TenantNameHelper class:
using Abp.Domain.Uow;
using Abp.MultiTenancy;
using Abp.Runtime.Session;
using System;


namespace AZProject.Utilities.Helpers
{
    public static class TenantNameHelper
    {
        public static string GetTenantNameFromSession(IAbpSession session, ITenantCache tenantCache)
        {
           
            if (session.TenantId.HasValue)
            {
                return tenantCache.Get(session.TenantId.Value).TenancyName;
            } else
            {
                //If userid has value, then this is host, otherwise not logged in (blank tenanacy)
                return session.UserId.HasValue ? "host": String.Empty;
            }

        }
        public static string GetTenantNameFromUnitOfWork(IActiveUnitOfWork unitOfWork, ITenantCache tenantCache)
        {
            if (unitOfWork.GetTenantId().HasValue)
            {
                return tenantCache.Get(unitOfWork.GetTenantId().Value).TenancyName;
            }
            else
            {
                //Assumes host as tenant
                return "host";
            }
        }

    }
}
  1. Added an injection for ITenantCache ineach of the services where the TenantNameHelper is used. Most were an ApplicationService or Controller as base class, so AbpSession was available.

Haven't fully tested yet, so if you have suggestions on where I might run into problems, let me know.

This was an extremely confusing post to address the issue of extending a localization source, which allows overriding existing entries and adding new ones. I wanted to organize things so that what I add for my application is separate from the AspNetZero supplied language files. To summarize the solution, you need to do the following assuming a project "YourProject" is the project that is provided from AspNetZero:

  1. In folder YourProject.Core/Localization, you find a YourProject folder with language files prefixed with "YourProject" (e.g. YourProject.xml, YourProject-de.xml, etc.
  2. You need to add a folder under YourProject.Core/Localization with a different name like "ExtendYourProject".
  3. In the new Folder, for any languages you want to extend, add a file with the SAME name as the language file you are extending (e.g., YourProject-de.xml). The file will contain any entries you want to override and any new entries.
  4. In the language configurer in YourProject.Core/Localization file YourProjectLocalizationConfigurer add the code:
            localizationConfiguration.Sources.Extensions.Add(
                new LocalizationSourceExtensionInfo("YourProject",
                    new XmlEmbeddedFileLocalizationDictionaryProvider(
                        typeof(YourProjectLocalizationConfigurer).GetAssembly(),
                        "YourProject.Localization.ExtendYourProject"
                    )
                 )
            );
           

Rebuild, and you should find that the extensions are now used. You do need to make sure that the "build action" for any files you add are showing "Embedded Resource". Any XML files that I added seem to be given that automatically in visual studio.

Hope that helps makes sense of a rather long involved post for something relatively simple in the end.

I encountered a problem with the "TargetNotifiers" column with update-database from version 11.2.1 to 11.4.0 on a migration 20220607073405_Add_Mass_Notifications. As that migration only attempted to add that column, I was able to proceed by removing the .cs file for the migration (in <project>.EntityFrameworkCore), rebuilding, and running update-database again.

Seems like this could be a problem for future releases if that migration is left in the release. Should it be removed from the aspnet-zero-core project?

Regarding setting up a session, this turned out to be easy to do with the Use method in IAbpSession:

        static async Task Main()
        {
            Console.WriteLine("Hello,  World!");
            using (var bootstrapper = AbpBootstrapper.Create<WebJobsModule>())
            {
                bootstrapper.Initialize();

                using (var appService = bootstrapper.IocManager.ResolveAsDisposable<ITraineeAppService>())
                {
                    ((Abp.Application.Services.ApplicationService) appService.Object).AbpSession.Use(null, 1);
                    var traineesAll = await appService.Object.GetAll();
                    Console.WriteLine("Traineees All Count {0}", traineesAll.Items.Count());
                }
                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();
            }           
        }

This problem was due to a local change to FileController.cs to require authentication using [AbpMvcAuthorize] By default, the File controller does not require authentication.

From communications (through [email protected]), I am looking at https://support.aspnetzero.com/QA/Questions/9571/Download-file-with-url-query-string-Auth-error#answer-d9417138-8ccb-839e-3ee7-39f755861c5f. as a means of protecting access.

Answer

I'm encountering the same problem. Cannot download either the latest version or previous version of a previous generated project. Tried in both Chrome and Edge browsers.

Showing 1 to 10 of 21 entries