Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

403
Vistas
ASP.net core 3.1: Javascript: window.open: Razor page

I'm trying to open a razor page method in my javascript and I'm not sure why it opens on http, not https even though the url is set to https.

Below is my code:

Javascript:

function openWindowWithPost(url, data) {
  var form = document.createElement("form");
  form.target = "_blank";
  form.method = "POST";
  form.action = url;

  form.style.display = "none";

  for (var key in data) {
    var input = document.createElement("input");
    input.type = "hidden";
    input.name = key;
    input.value = data[key];
    form.appendChild(input);
  }
  var input = document.createElement("input");
  var token = $('input:hidden[name="__RequestVerificationToken"]').val();
  input.name = "__RequestVerificationToken";
  input.type = "hidden";
  input.value = token;
  form.appendChild(input);

  document.body.appendChild(form);
  form.submit();
  document.body.removeChild(form);
}

function ButtonClickedEvent(){
    var inputJSON = '{"id": 1}';
    var url = location.protocol + '//' + location.host + '/Report/?handler=BatchReport';
    console.log('url: ' + url);    
    openWindowWithPost(url, JSON.stringify(inputJSON));        

}

Razor Page: Code behind:

[Authorize]
[HttpPost]
public async Task<string> OnPostBatchReport([FromBody] InputParameter parametersJSON)
{
    var somestring = await getstring(parametersJSON);
    return somestring ;

}

Startup.cs:

public void ConfigureServices(IServiceCollection services)
{       

    services.AddRazorPages().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
    services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");


    services.Configure<CookiePolicyOptions>(options =>
    {
        // This lambda determines whether user consent for non-essential cookies is needed for a given request.
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.Unspecified;                
        options.Secure = CookieSecurePolicy.SameAsRequest;                
        options.HandleSameSiteCookieCompatibility();
    });

    // Sign-in users with the Microsoft identity platform
    services.AddMicrosoftIdentityWebAppAuthentication(Configuration);

    services.AddControllersWithViews(options =>
    {
        var policy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .Build();
        options.Filters.Add(new AuthorizeFilter(policy));
    }).AddMicrosoftIdentityUI();

    
}

My website is hosted at https://localhost:12345 and when I click on the button, I call the ButtonClickedEvent javascript function to open the report page in a separate tab. This tab has the protocol as http, not https.

Any help is appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Regarding the application hostURL it usually depends on launchsettings.json file configuration.

To resolve this issue you should set applicationUrl under launchsettings.json as what you want it to while your application run.

launchsettings.json:

enter image description here

Hope it would guided you accordingly.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda