asp.net web表单动态路由 [英] asp.net webforms dynamic routing

查看:171
本文介绍了asp.net web表单动态路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网页的SQL Server表和创建每一页都有塞。我一直在做的是表中的foreach页面获得蛞蝓和做到这一点:

  routes.MapPageRoute(page.Slug,page.Slug,〜/ page.aspx?ID =+ page.Id,真,新System.Web.Routing.RouteValueDictionary { {ID,page.Id}});

到目前为止,这完美的作品。我的问题是,这个运行在应用上Global.asax文件启动,所以如果我创建一个新的页面,除非我重新启动IIS中的网站映射不起作用。我被 haacked 但尚未阅读这篇文章能够创建一个页面就会自动刷新所有routing..any想法时,得到它尚未而不工作肯定这是否会解决这个问题,在理论上原因在哪里?

因此​​,在使用RouteMagic,当我得到错误对象引用不设置到对象的实例在这一行:

  RouteTable.Routes.RegisterRoutes(〜/配置/ Routes.cs);


解决方案

您可能正在丢失的动态编译。检查样本code那里动态编译code

  VAR总成= BuildManager.GetCompiledAssembly(〜/配置/ Routes.cs);
VAR注册商= assembly.CreateInstance(路线)作为IRouteRegistrar;

此外,确保 Route.cs 设置为内容,因此不会静态编译。

I have a table in sql server with pages and each page created has a slug. What I've been doing is foreach page in the table get the slug and do this:

 routes.MapPageRoute(page.Slug, page.Slug, "~/page.aspx?id=" + page.Id, true, new System.Web.Routing.RouteValueDictionary { { "id", page.Id } });      

so far this works perfectly. My issue is that this runs on global.asax file on application start so if I create a new page that mapping doesn't work unless i restart the website in iis. I was reading this post by haacked but haven't been able to get it to work yet and not sure if this would solve it, cause in theory when creating a page it should refresh automatically all routing..any ideas?

So when using RouteMagic I get the error "Object reference not set to an instance of an object" at this line:

RouteTable.Routes.RegisterRoutes("~/Config/Routes.cs");

解决方案

You are probably missing dynamic compilation. Check in the sample code where it dynamically compiles the code

var assembly = BuildManager.GetCompiledAssembly("~/Config/Routes.cs");
var registrar = assembly.CreateInstance("Routes") as IRouteRegistrar;

Also, make sure Route.cs is set to Content so it doesn't statically compile.

这篇关于asp.net web表单动态路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆