English 中文(简体)
Page. RouteData 返回 WebResources. Axd 的网络资源?
原标题:Page.RouteData returning WebResource.axd?

我有一个规则在我的Global.asax喜欢这样:

RouteTable.Routes.MapPageRoute("defaultRoute", "{*value}", "~/default.aspx")

基本上,任何实际不存在的页面都被重置为默认的.aspx。当该页面加载时,我在Page_Load sub中使用了以下内容:

Dim prospect_url As String = Page.RouteData.Values("value")

然后,我把它转换成一个会话变量,像这样:

Session("prospect_url") = prospect_url

最终, 个人被重新定位到另一个页面... 我需要再次访问这个值, 但当我执行以下操作时:

Dim prospect_url As String = CStr(Session("prospect_url"))

我得到了WebResources, 算作前景的值。 什么?!!!!!!!!这是从哪来的?

最佳回答

That global rule applies to any resource being requested, including image files, script files, and any other resource (such as that WebResource.axd you re seeing).
So what happened here is that your route table rule caused it to save each request into your session variable, overwriting the last value every time, and by the time you looked at the session variable yourself, it was left at WebResource.axd (it could be something else on a different instance).

I have one solution to that approach on my blog:
http://beemerguy.net/blog/post/How-to-support-dynamic-URLs-in-ASPNET-(by-example).aspx
But it s in C#, and it should be straightforward to translate into VB.NET.

但基本上,您应该在同一请求中处理前景URL值,而不是依赖会话变量,因为其他同时提出的请求可以在到达该值之前覆盖该值。

问题回答

尝试下面的代码 :

 protected void Application_Start(object sender, EventArgs e)
 {
     RegisterRoutes(RouteTable.Routes);

     ...
 }

 private static void RegisterRoutes(RouteCollection routes)
 {
    routes.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler()));

    ...
 }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签