updatepanel not working Url routing - c#

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]+" } });

Related

unwanted html form action using URL Routing in ASP.NET 4 Web Forms

I have a working ASP.NET 4 Web Forms site, but now I need to apply url routing
I have on my global.asax:
protected void Application_Start(object sender, EventArgs e)
{
routes.MapPageRoute(
"Route1",
"Page/{P1}/{P2}/{P3}/{P4}",
"~/Page.aspx"
);
}
It's mapping fine my route, but the resulting html form has a wrong action attribute, which consists on the value of the url param {P4}
Writting in Page_Load
Form.Action = Request.RawUrl;
doesn't work neither. But it's working fine if I write the actual url:
Form.Action = "Page.aspx?params...";
I hope you could help

URL Routing .Net 4.5 Webforms

I have a webforms app that I would like to add some routing in so when a user types in www.mySite.com/Brd it will take them to a specific page. I can get this to work if I put an argument in, however I don't want any. Here is what I have in my application start method
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoute(System.Web.Routing.RouteTable.Routes);
}
void RegisterRoute(System.Web.Routing.RouteCollection routes)
{
routes.MapPageRoute("Route1", "Rep", "~/SalesRep/SalesRepHome.aspx");
routes.MapPageRoute("Route2", "Brd", "~/Board/BrdLogin.aspx");
}
The route for the Brd takes me to www.mysite.com/BrdLogin.aspx without the subdirectory and the Rep route does nothing. Could someone point me in the right direction?
Try adding this line to your RegisterRoutes method...
routes.EnableFriendlyUrls();
Make sure you're also referencing the Microsoft.AspNet.FriendlyUrls assembly
Also, try putting a forward slash after Rep and Brd e.g.
routes.MapPageRoute("Route1", "Rep/", "~/SalesRep/SalesRepHome.aspx");
routes.MapPageRoute("Route2", "Brd/", "~/Board/BrdLogin.aspx");

404 error with MapPageRoute() routing a aspx page within a folder

Trying to route in webforms, getting a 404.
I have set up my global.asax.cs file as follows using System.Web.Routing;
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
private void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("ProfilePage",
"Profile",
"~/Manager/Profile.aspx");
}
profile.aspx is located within the manager folder. No idea why it's not working. Would be grateful if someone could make some suggestions I am fairly new to asp.net.
I am expecting the url localhost:60008/Manager/Profile/ to load the Profile.aspx page.
The second parameter specifies the URL. Try:
routes.MapPageRoute("ProfilePage",
"Manager/Profile",
"~/Manager/Profile.aspx");
You have it right the first time. Here a valid routing
routes.MapPageRoute("", "YourPage", "~/Your/full/url.aspx", true);
The first para can be let empty, the second is the one you are going to use, the third is the url of your page, the last [optional] is to check if the file exist physically or not.
I believe where the error comes is how you use it, for a hyperlink you would say
NavigateUrl="~/YourPage"
In a html anchor
href="~/YourPage" runat="server"
In the browser address bar it will show like this http://YourDomain.com/YourPage/
That's the way it works for me. Personally having to put the folders in there defeat the purpose of using routing no?

How to change content based on the page name instead of querystring in asp.net

I've a site, we are using ASP.NET 4.0, and right now our products content is managed like this
www.franko1.com/products.aspx?serie=2000
where the querystring serie is the product ID, so its value is taken and then the contents is extracted from the database.
Now for SEO reasons, we've been asked to change the urls, so now they have to look like this:
What the boss want | Current Urls
--------------------------------------------------------------------------------
www.franko1.com/Relief_Valves | www.franko1.com/products.aspx?serie=2000
www.franko1.com/Inline_Flame_Arrester | www.franko1.com/products.aspx?serie=1000
www.franko1.com/Vent_Hatch | www.franko1.com/products.aspx?serie=3000
and so on ...
Right now, we are using a masterpage and the products.aspx and as I said, we take the querystring serie and we show the content based on its value, I have no idea how to do this using asp.net, I have read about ISAPI_Rewrite but I was wondering if there is a technique to approach this without dealing with the IIS server....
Well I don't know if I was clear, It is hard to explain,
No need for that. You can achieve this via routing (It's not just for MVC).
Routing has been available as a stand alone module for a while now, but with ASP.Net 4.0 you can now use routing for WebForms just as easily as you can with MVC.
You will need to add some routing to your Global.asax
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("Products", "Products/{Name}", "~/Products.aspx");
}
}
And with that you can now reference the route values in your page like so:
protected void Page_Load(object sender, EventArgs e)
{
string prodName = Page.RouteData.Values["Name"].ToString();
//Do lookup, etc...
}
Your URLs will end up looking like this:
www.domain.com/products/Relief_Valves
www.domain.com/products/Widgets
www.domain.com/products/TrashCans
etc..
Nice and easy... and clean!
URL rewriting was made just for exactly this purpose. The problem is that it really doesn't work with variable content directly appended to the root URL. There really isn't enough information for URL routing to separate such URLs from the rest of your URLs.
Would your boss accept www.franko1.com/p/Relief_Valves ?

RDLC Alternating rows

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

Categories