从asp.net中重写的URL获取标题? [英] Get the title from a rewritten url in asp.net ?

查看:97
本文介绍了从asp.net中重写的URL获取标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经使用 urlrewriter.net 重写了一个URL,所以这样的URL是:

Projects.aspx/ProjectId = 4 成为:Project/trains-4.aspx.

但是我的问题是,我需要从此处为火车"的网址获取标题.
因此,iam使用了:Request.PathInfo,但它无法正常工作.因此,有什么方法可以从url中获取火车".

注意:request.querystring获取的初始URL为:"Projects.aspx/ProjectId = 4"

在此先感谢.

Hi all ,

I have used the urlrewriter.net to rewrite a URL, so a URL like this :

Projects.aspx/ProjectId=4 became: Project/trains-4.aspx.

But my problem is that i need to get the title from the url which is "trains" here.
So iam using : Request.PathInfo, but it is not working.So is there any way to get the "trains" from the url .

Note: the request.querystring gets the initial url which is:"Projects.aspx/ProjectId=4"

Thanks in advance.

推荐答案

我还没有使用urlrewriter.net,但是URL重写通过在服务器配置中指定重写规则来实现,例如,如果您使用的是IIS7,则URL重写工具用于此目的,并且只有服务器有权访问该规则.因此,我想无论您在C#中做什么,都只会得到长的/原始URL,而不会得到重写的URL.重写URL只是一个正则表达式,它在服务器级别用新的URL替换了旧的URL,因此您的C#代码不太可能读取新的URL,因为服务器只是在内部将您重定向到新的URL.您可以尝试指定反向写入规则,也可以仅将新URL作为带有原始URL的GET参数发送(不确定精确度,但大致思路).

看看这是否对您有帮助: ASP.NET中的URL重写 [ ^ ]

为您准备的更多:使用ASP.NET进行URL重写 [
I haven''t used urlrewriter.net but URL rewriting works by specifying a rewrite rule in server configurations i.e. if you are using IIS7 then URL Rewrite tool is used for the purpose and only server has access to the rule. So I would imagine no matter what you do in C#, you would only ever get the long/original URL and not the rewritten one. The rewrite URL is just a regular expression which replaces old URL with the new one at the server level, so your C# code doesn''t quite get to read the new URL as the server just internally re-directs you to the new URL. You can may be try specifying a reverse write rule or just send the new URL as a GET parameter with the original URL (not sure how exactly, but a rough idea).

See if this does anything to help you : URL Rewriting in ASP.NET[^]

something more for you : URL Rewriting with ASP.NET[^]

Turns out, if you have a finite number of URLs to rewrite then you can define them in the web.config and then u can read in your C# code using the ConfigurationManager class. Hack around with it.

Cheers...


您正在使用一些使我感到困惑的术语,但是我建议比较Request.Url和Request.RawUrl中的值.也许其中之一具有您想要的价值.
You are using some terminology that is confusing me, but I suggest comparing the values in Request.Url and Request.RawUrl. Perhaps one of those has the value you are looking for.


这篇关于从asp.net中重写的URL获取标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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