SSRS reports with .Net Core 3.1 MVC application - ssrs-2012

I am trying to display the SSRS report in a .Net Core 3.1 MVC application.
I tried to implement the approach mentioned in
https://alanjuden.com/2016/11/10/mvc-net-core-report-viewer/?unapproved=58532&moderation-hash=321d5350c96d2fcf83baa4c939bbdf53#comment-58532
public class ReportsController : AlanJuden.MvcReportViewer.ReportController
{
protected override ICredentials NetworkCredentials
{
get
{
//Custom Domain authentication (be sure to pull the info from a config file)
return new System.Net.NetworkCredential("username", "password");
//Default domain credentials (windows authentication)
//return System.Net.CredentialCache.DefaultNetworkCredentials;
}
}
protected override string ReportServerUrl
{
get
{
//You don't want to put the full API path here, just the path to the report server's ReportServer directory that it creates (you should be able to access this path from your browser:
return "https://YourReportServerUrl.com/ReportServer/ReportExecution2005.asmx";
}
}
public IActionResult ProcessReport()
{
var model = this.GetReportViewerModel(Request);
model.ReportPath = "reportPath";
return RedirectToAction("ReportViewer", model);
}}
but it is not working with the latest framework.
I am getting following error while running the project - Error screenshot
Any help is appreciated.
Thanks!

The same thing happened to me, in my case I needed to install the same package that tells you to install
Install-Package System.ServiceModel.Http -Version 4.1.0
or in the nuget look for the package System.ServiceModel.Http

I tried different workarounds with latest .NET Core including the one you mentioned from Alan Juden. However the easiest thing that worked for me is to create a plain .NET WebForms site using the Report Viewer control from Microsoft. It was still a lot of code but this is solid because the Report Viewer control has been around for many years.
In my case it is showing SSRS Report from Angular UI, but the same will work with MVC or any other Web UI because you will actually redirect/navigate to another url (WebForms aspx page).
More details here.

Related

Error trying to scaffold a view in ASP.NET Core 6.0 MVC

I'm trying to scaffold a new razor view using Visual Studio. I select a template, my model and my DbContext, then I get the error message shown below.
Things to note. My models, my DbContext and my website are all in different projects. From the message below I am using AddDbContext and I have a constructor that accepts a DbContextOptions<TContext> parameter.
I read a comment on a blog post that the issue is because my context is in another project. The comment referenced something about the need to inject the Configuration into the DbContext to get the connection string and manually add it in the OnConfiguring override.
I can't find any examples if this is correct or how to set it up. Any help would be appreciated.
EDIT:
Testing out the theory from the blog comment I mentioned above, I added this section into my DbContext. ConnectionString is a hardcoded string constant with my connection information. This does work and allow me to scaffold, so the question still remains. How can I inject this connection string into my DbContext to allow the scaffolding to work?
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(ConnectionString);
}
else
{
base.OnConfiguring(optionsBuilder);
}
}
EDIT: So after making this change, I checked in the code and had another developer pick it up. It appears this section above just needs to be there to allow scaffolding to work. He never changed the connection string to point to his environment. He no longer got the error above it just worked.
I am not sure about what is the actual problem but it seems like we were having problems creating DbContext at design time. I manually added the code below and it's working now. It's just a temporary solution tho.
public AppDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=JwtTemplate;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
return new AppDbContext(optionsBuilder.Options);
}
Reference: https://stackoverflow.com/a/70559350

Model Validation using Data Annotations not working on Mac VS.NET

I created a new Web API Application on MacOS with VS.NET. I added a model with the following code:
public class PersonAddRequest {
[Required]
public string FirstName { get; set; }
public string LastName { get; set; }
}
Then I created a Web API Controller like so:
[Route("api/[controller]")]
[ApiController]
public class PeopleController : ControllerBase {
[HttpPost]
public IActionResult Post(PersonAddRequest model) {
return base.Ok(model);
}
}
When using PostMan I post JSON as so (note firstName is missing):
{
"lastName":"McDonalds"
}
When I run this code on a Web API Application created on a Windows OS validation works as expected. However, when I create the project in MacOS validation doesn't work.
When I create the project in Windows OS then open and run it on MacOS, validation works!
So my question, is this a feature that is missing as part of the scaffolding on VS.NET for Mac?
You require the FromBody attribute for the body argument:
[Route("api/[controller]")]
[ApiController]
public class PeopleController : Controller
{
[HttpPost]
public IActionResult Post([FromBody]PersonAddRequest model)
{
return Ok(model);
}
}
This is required for model validation.
Here's an example git repo using this form of model validation that is confirmed working on MacOS Mojave 10.14.4
I want to thank #nelsontruran for helping me explore VS.NET on Mac. I'm actually running a later version of the Mac (10.14.5 Mojave). However, the version had nothing to do with the original problem.
Thru the patients and persistent help of #nelsontruran I recreated the project but instead of using the suggested templates I dug around a little for the correct application (don't trust the suggested applications in VS.NET). Here's the step-by-step instructions on how to create an API that automatically performs model validation:
Open VS.NET for Mac
Create a new project
When prompted to "Choose a template for your new project", select "App" under the ".Net Core" section on the left side pane.
On the right side pane, select API
From there you can review #nelsontruran's example on git to see the magic of Model Validation.
I believe I might have been choosing "Web Application" thinking that it would be the same in Mac as it is in Windows.
A simple oversight on my part. I hope this helps someone who was confused and struggling like me.
Thank you again to #nelsontruran!!!

Error with Asp.net MVC3 app after loading into Visual Studio 2012

I opened an existing ASP.NET MVC3 project that formerly worked just fine in a newly built machine with Visual Studio 2012 installed.
I'm now getting null exceptions in the following code. After a User logs in, the following code is then executed to perform page fragment-level access.
The null exception is thrown on the WebViewPage.User object. However, when in debug mode, I can actually inspect a real instance of the object (see image below)
public static class WebViewPageExtensions
{
public static bool HasAccess(this WebViewPage pg)
{
if (pg == null) throw new ArgumentNullException("WebViewPage is null");
if (pg.User == null) throw new ArgumentNullException("WebViewPage User is null");
return pg.User.IsInRole(User.ACCESS_LEVEL_A) || pg.User.IsInRole(User.ACCESS_LEVEL_B);
}
}
Note: this could be something with the way my environment is configured (web.config maybe?), but not really sure where to start. As it is, the code that this is happening on is the same code running in production and the former developer environment.
All the references are still referring to the ASP.NET MVC3 version of the framework running on the .NET 4.0 platform.
EDIT: Here's the callilng code from a Razer view:
#if (this.HasAccess()) {
<div>
HTML here
</div>
}
Any thoughts?
Please read section "Installing ASP.NET MVC 4 breaks ASP.NET MVC 3 RTM applications" from link http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253815. Follow setps "Required updates" to update your MVC 3 app. If you havent noticed, MVC4 gets installed with VS2012 and this is documented behavior.

ASP.NET Output Caching not working after upgrade from MVC2 to MVC4

We have an existing MVC2 project that we just upgraded to MVC4 following first these steps to get to MVC3, then these steps to get to MVC4.
Output caching had been successfully working for a long time in our MVC2 project, but it does not work after the MVC4 version.
I've added a simple controller to test caching:
public class TestController : Controller
{
[OutputCache(Duration = 600, VaryByParam = "*")]
public ActionResult CacheTest()
{
return Content(DateTime.Now.ToLongTimeString());
}
}
Each time i refresh this page, the time output to the browser changes.
Creating a new MVC3 project in this same solution, then upgrading to MVC4, then copying this same code over works as expected.
So there must be something somewhere in our existing code or configuration that is breaking output caching.
I've also tried stripping out a ton of stuff from the web.config file thinking something there was causing problems - no luck.
Any suggestions on how to fix or debug this?
UPDATE:
Rendering the CacheTest action above in any view will display cached results - i.e. the date does not change on each refresh:
<% Html.RenderAction("CacheTest", "Test"); %>
Why does that work, but the action url from a browser is never cached?
Turns out this was an issue with a third party library - 51Degrees. This was an issue introduced into a recent version of this library. In the process of converting from MVC2 to MVC4 I installed the nuget package which was a few versions later than the previous version I was using.
False alarm - nothing to do with the ASP.NET MVC upgrade or anything ASP.NET related.

migrating from ASP.NET profiles in website to web application project (cannot handle propertygroups)

I am transfering my solution from a website project to a web application project. In the process I am migrating profiles as well. Part of migrating from website to web application is that I need to write my own Profile-class as described here: http://leedumond.com/blog/asp-net-profiles-in-web-application-projects/
This works fine for all my existing properties except those belonging to a propertygroup.
In my website I had a propertygroup called "Facebook" for storing facebook-specific details. But in my web application project I cannot access these properties. Instead it seems to overwrite my existing properties with new empty ones. When I look in the database I can see that the old properties were stored as eg. "Facebook.FacebookUserId" whereas the new properties are stored as just "FacebookUserId" (without the "Facebook"-prefix). So my question is how to get my old properties ? I have tried creating propertygroups as proposed in the link above, but this just leads to a new xml-property (serializing the class).
Right now I am fetching the properties like this:
public long FacebookUserId
{
get
{
return (long)GetPropertyValue("FacebookUserId");
}
}
I have also tried:
public long FacebookUserId
{
get
{
return (long)GetPropertyValue("Facebook.FacebookUserId");
}
}
But none of this seems to work.
Any help is appreciated
thanks
Thomas
I ended up doing a search and replace on the Facebook-prefix, and removed it

Resources