We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Issues creating asp.net core web service for PDF Viewer

Thread ID:

Created:

Updated:

Platform:

Replies:

150911 Jan 24,2020 03:41 AM UTC Jan 24,2020 03:58 PM UTC ASP.NET Core - EJ 2 3
loading
Tags: PDF Viewer
Kenneth Russo
Asked On January 24, 2020 03:41 AM UTC

I am having two issues:
  • I get a 400 when the PDF Viewer (see pdf-viewer.html) attempt to call the web service PdfViewerController.  If I use your online web service, the simple viewer works properly.
  • If I launch the viewer from a different web site (some other port on local host) I get CORS errors.
This is on Mac OS (latest) and Visual Studio 2019 with .net core 3.1.

I have reviewed various threads and downloaded various services, none seem to work.

I have attached my test, but again, this is on a Mac.  I had limited success hosting from Windows (embedded viewer worked, still had CORS issues, I googled, no luck).

Thank you for your time.

Kenneth Russo

Attachment: PdfViewerService_660c375f.zip

Kenneth Russo
Replied On January 24, 2020 04:00 AM UTC

Actually table the CORS issue for now, lets just focus on getting the api working on asp.net core.  Thanks Ken

Samantha Digby [Syncfusion]
Replied On January 24, 2020 02:52 PM UTC

Incident 262261 has been created for this forum.  


Rajasekar G [Syncfusion]
Replied On January 24, 2020 03:58 PM UTC

 
Hi Kenneth, 
 
Sorry for the inconvenience,  
 
To resolve this issue, you have to configure the cross origin and controller routing in startup.cs. Also refer the Microsoft.AspNetCore.Mvc.NewtonsoftJson package with version 3.1.1 for parsing the JSON object in controller. Please find the code snippet below.  
 
public class Startup 
    { 
        public Startup(IConfiguration configuration) 
        { 
            Configuration = configuration; 
        } 
 
        public IConfiguration Configuration { get; } 
        readonly string MyAllowSpecificOrigins = "MyPolicy"; 
        // This method gets called by the runtime. Use this method to add services to the container. 
        public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddControllers(); 
           services.AddMemoryCache(); 
            services.AddControllers().AddNewtonsoftJson(options => 
            { 
                // Use the default property (Pascal) casing 
                options.SerializerSettings.ContractResolver = new DefaultContractResolver(); 
            }); 
 
            services.AddCors(options => 
            { 
                options.AddPolicy(MyAllowSpecificOrigins, 
                builder => 
                { 
                    builder.AllowAnyOrigin() 
                      .AllowAnyMethod() 
                      .AllowAnyHeader(); 
                }); 
            }); 
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); 
            services.Configure<GzipCompressionProviderOptions>(options => options.Level = System.IO.Compression.CompressionLevel.Optimal); 
            services.AddResponseCompression(); 
        } 
 
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 
        { 
            if (env.IsDevelopment()) 
            { 
                app.UseDeveloperExceptionPage(); 
            } 
            else 
            { 
                app.UseHsts(); 
            } 
            app.UseHttpsRedirection(); 
            app.UseRouting(); 
            app.UseAuthorization(); 
            app.UseCors(MyAllowSpecificOrigins); 
            app.UseResponseCompression(); 
            app.UseEndpoints(endpoints => 
            { 
                endpoints.MapControllers().RequireCors("MyPolicy"); 
            }); 
        } 
    } 
 
 
We have created the simple PDF viewer web service application in .NET core 3.1 and provided in the below link. 
 
 
Note: Run the PDF viewer web service application and provide the launched URL to the serviceUrl property of PDF viewer control. 
 
Please try the provided web service application in your and provide the more details if it still facing problem on web service in your environment. 
 
Regards, 
Rajasekar 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon