I've been working on an MVC3 app and a recent requirement is that it has a couple of dynamically generated reports. So I added a single webbform with a reportviewer and a couple of reports (.rdlc). But when I try to set Conditional row-fills eg
=IIf(RowNumber(Nothing) Mod 2, "Blue", "Red") // Won't acctually use those colors but you get the gist
But the resulting background is still white.
I tried out the exact same webform in a true blue Webform application and from there it rendered properly. I've checked that my MVC project contains every reference used in my Webforms testproject and added .aspx and .rdlc to ignored routes in 'Global.asax.cs'.
Why the Hybrid Horror?
I can not change from Clientside Reporting generation to Serverside due to Performance Reasons, nor can I use a different/remote server because the environments (yes plural) lack of bandwidth and connectivity. And I'd prefer not having to add a separate app pool just for the reportviewer (again performance issues).
EDIT1:
Global.asax
public class MvcApplication : System.Web.HttpApplication {
public static void RegisterGlobalFilters ( GlobalFilterCollection filters ) {
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes ( RouteCollection routes ) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.rdlc/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start () {
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
Report.aspx
....
</rsweb:ReportViewer>
<asp:XmlDataSource ID="reportsDS" runat="server"
DataFile="~/Reporting/ReportSettings/Reportlist.xml"
XPath="Reports/Report" />
<asp:ScriptManager ID="scriptmanager" runat="server" />
....
Report.aspx.cs
// Some configuration initialization and the regular Page_Init + Page_Load assigning
// default values
protected void changeReport() {
ReportViewer.Reset();
ReportDataSource RDS = new ReportDataSource( /* grabbed from a combination of applicationsettings and input parameters */
ReportViewer.LocalReport./* adding datasource and setting paths, names, etc. */
}
EDIT2:
Added the code to give better context to what I'm doing but seeing that the Code acctually works when published from a Webforms project I'm guessing that ReportViewer performs some sort of Blackmagic requests that the Global.asax isn't particularly fond of. But despite my best firebug efforts I haven't been able to find that brand of magic yet.
I managed to solve the problem by modifying the Page_Init
protected void Page_Init( object sender, EventArgs e ) {
...
ReportViewer.LocalReport.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));
...
}
Feels like a hack, so I'll hold of a day or two before accepting this answer
Related
My Code for the Route looks like this:
RouteTable.Routes.MapPageRoute("IDP", "Person/{IDP}", "~/Person.aspx")
And now i want to get the Data on a Form, normally it works like this:
int id = Convert.ToInt32(Page.RouteData.Values["IDP"]);
But everytime i try to get the Data from the Route e.g.: http://PC-81/SkillDatenbank/Person/1
I get no Data from the Value (it is empty!)
I am using ASP.Net 4.5 with Web Forms.
Edit: I made an new Project and tested and it didnt work either
What am i Doing wrong? in the Last Project it did work like this :(
Can you help me?
Your problem ist probably located in your Routing table. I have created a WebForms project to test this out.
Open up your Global.asax (or whereever you store your RouteConfig; default is App_Start/RouteConfig.cs) and check your RegisterRoutes method. Add the following line to it, if it isn't already present.
void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
/* ... additional routes */
routes.MapPageRoute("","Person/{IDP}", "~/Person.aspx");
}
In your Application_Start there should be a line like this, if you use the default configuration with in the App_Start folder: RouteConfig.RegisterRoutes(RouteTable.Routes);
If you defined your routes in your global.asax.cs it is just RegisterRoutes(RouteTable.Routes);
If you now access your Page via http://PC-81/SkillDatenbank/Person/1 the RouteData dictionary will contain 1 set of data, like this:
Following code has worked for me, I have moved additional routes to top of the function.
Also, in my case RedirectMode is off because I'm using Jquery in my code and inorder to make a Webmethod work, I have turned off RedirectMode.
void RegisterRoutes(RouteCollection routes)
{
/* ... additional routes */
routes.MapPageRoute("","Person/{IDP}", "~/Person.aspx");
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
}
I'm running into a bit of an issue. My postbacks are causing my asp.net application pages to jump back to the top of the page even though they are inside update panels.
when i use this routing updatepanel stop working
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("UProfile", "{ID}", "~/UProfile.aspx");
}
but when i use this code it works fine, but i want the simplest URL
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("UProfile", "Users/{ID}", "~/UProfile.aspx");
how should i solve this problem ?
I have tried a couple different solutions, that did not work:
1) http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
2) http://www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms
This will route will target root Url because there is no any specific identifier to map it properly. I will rather suggest to write a route constraint so you can decide when to use the user details page after validating the passed parameter.
You can add routers in Asp.net Webforms too. Check the following link.
http://www.shubho.net/2011/02/aspnet-mvp-url-routing-webforms-part3.html
The possible solution would be...
RouteTable.Routes.MapPageRoute("UProfile",
"{ID}",
"~/UProfile.aspx",
false,
new RouteValueDictionary { { "ID", "1" } }, new RouteValueDictionary { { "ID", "[\d]+" } });
I am currently working in a brownfield ASP.NET MVC 3 project in VS2010.
In this project, views and controllers are in separate projects. This is not something that I have seen before. In each action method there is no explicit stating of view name as below.
return View("viewName",passingModel);//projects where controllers and views are in same
I have done this implicitly in VS2012 by right clicking on the view and do add view. So I was not bothered about where is this connection between action method's return view and the view is stated.
Unlike in VS2012, in VS2010 I can not navigate to the view that is related to one particular action method by right clicking on View and doing go to view.
I tried to understand this by doing this small experiment. I created a Controller and created a Action Method call xxxx and I created a view for that implicitly as mentioned above and searched the word xxxx in entire solution but this word only appeared in controller and in the view.
So, I was unsuccessful in finding the answer. I think visual studio itself creating its own mapping to achieve this.
I would like to know who these implicit connections are created among action methods and views to understand what is going on in my project.
Edit:
Both the projects which contains controllers and views are class libraries. not asp.net mvc projects.
Global.aspx file contains this:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
protected void Application_Start()
{
DependenciesHelper.Register(new HttpContextWrapper(Context));
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RoutingHelper.RegisterRoutes(RouteTable.Routes);
}
protected void Application_End()
{
//Should close the index
//If this method is not executed, the search engine will still work.
SearchService.CloseIndex();
}
The mapping is fairly straightforward. For example if you have a controller called "MyBrilliantController" and an action method called "MyExcellentAction" which returned just return View(); it would map to (in the UI project) ~/Views/MyBrilliant/MyExcellentAction.cshtml
The only time where this is different is when you are working with "Areas" - but the mapping is effectively the same, it would just consider the area folder first (ie ~/Areas/MyArea/Views/MyBrilliant/MyExcellentAction.cshtml)
Hope that helps.
EDIT - You can also specify namespaces in the global.asax file on each route for the engine to find controllers
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}, // Parameter defaults
new string[] {
// namespaces in which to find controllers for this route
"MySolution.MyControllersLib1.Helpers",
"MySolution.MyControllersLib2.Helpers",
"MySolution.MyControllersLib3.Helpers"
}
);
}
i want to route Default.aspx to another URL when page starts.
my global.asax is like this :
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute(
"Default", // Route name
"My Site", // URL with parameters
"~/Default.aspx" // Parameter defaults
);
}
should i write a handler for my purpose?
(i found some samples for .net 3.5 and MVC but what about .net 4 web forms)
if yes how can i write it?
EDIT:
what this line exactly do?
routes.Add("Default", new Route(string.Empty, new RouteHandler("~/Default.aspx")));
i am using web forms -> Not MVC
thanks in advace
Here's a specific example of how to deal with routing on asp.net 4.0 web forms (it's just under the mvc part).
http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
The way you are approaching it is fine. You do have an error in the second parameter of your route. Well perhaps not an error, I dislike spaces in urls as they are actually the encoded spaces. Check out the guide.
Just noticed your edit.
Adding the route essentially creates a mapping between a url or url pattern (which you have as string.Empty which is a problem) and a handler which serves the request(You specify RouteHandler which I don't believe actually exists?). .net Provides a PageRouteHandler which allows you to specify which page responds to your request and deal with a couple other details like security defined on the physical structure of your site. Internally, MapPageRoute is simply calling routes.Add but using the PageRouteHandler.
I am using a custom route handler for a webforms application. I am using routes to determine localization. ie:
if the url has es or fr in the route it will load either spanish or french resources.
for example:
www.someroute/es/checkstuff/checkstuff.aspx
will load:
www.someroute/checkstuff/checkstuff.aspx with the spanish resources.
I am configuring the custom routes in global.asax via:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
foreach (var value in _customRoutes)
{
routes.Add(value.RouteName, new Route(value.Route, new CustomRouteHandler(value.ResolvedRoute)));
}
}
where _customroutes is a list of routes.
Is there a way to do this with some kind of pattern matching so I can avoid adding a specific route for each page in the application. While I know I could use a t4 template to generate the routes, I guess I am looking for a dynamic way to create the list
I discovered that it was simpler to use MapPageroute than route.Add. With MapPageRoute I was able to use wildcards and with two entries:
routes.MapPageRoute("Spanish", "es/{*page}", "~/{page}");
routes.MapPageRoute("Kreyol", "fr/{*page}", "~/{page}");
I was able to provide the required routing for Spanish and Kreole pages.
Thanks to all for your help.
I would handle the language-part through some plain old Rewrite with an HttpModule in the BeginReguest handler and let the Routing engine take care of the rest.
Remember that the Routing mechanism takes place far later than BeginRequest so you can safely determine the language, set the CultureInfo on your thread and rewrite the request url to no contain the language-part, and your Routing would never know about it.