使用C#在asp.net中重写url以在页面初始化级别读取url以查找页面 [英] url rewrite in asp.net with c# to read a url at page init level to find the page

查看:135
本文介绍了使用C#在asp.net中重写url以在页面初始化级别读取url以查找页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使像Google这样的动态网站提供在线网站的开发和设计服务,
我已经完成了数据库和设计的所有工作,但是如何在加载时获取URL
Web应用程序的
如果找不到页面,则错误404英亩

在google

网站网址为www.website.google.com/ourlwebsitename
这里我们的网站名称是用户创建名称的示例.
我想做的同样的事情.

www.mywebsite.com/userchiceaname

I need to make dynamic website like google provide services of develop and design on line website,
I have completed all things of database and design, but how could i get the url at loading time
of the web application
if page not found then 404 error acre

in google

the website url would be www.website.google.com/ourlwebsitename
here ourlwebsitename is as a example of user created name.
same thing I want to do.

www.mywebsite.com/userchiceaname

推荐答案

您好,

您可以使用URL重写器/HTTP模块来完成此操作.
在这里,我写了一篇有关该主题的文章: How- :创建一个简单灵活的URL重写器 [ ^ ]

基本上,您需要创建一个HttpModule并挂接到HttpApplication.BeginRequest事件(必须挂在HttpModuleInit(HttpApplication context)中).然后在BeginRequest EventHandler中,可以使用((HttpApplication)sender).Context.Request.Url访问当前URL.

在阅读后,您可以将用户重定向(((HttpApplication)sender).Context.Response.Redirect())或重写(((HttpApplication)sender).Context.Response.RewritePath)到目标页面(并且url文件夹名称将由querystring参数传输).

希望这会有所帮助.

最好的问候,并且一如既往:祝您编程愉快:),
克里斯
Hi,

You could accomplish this by using a URL Rewriter / HTTP Module.
Here, I wrote an article about this topic: How-to: Create an easy and flexible URL-Rewriter[^]

Basically you need to create a HttpModule which hooks to the HttpApplication.BeginRequest event (must be hooked in the Init(HttpApplication context) of the HttpModule). Then in the BeginRequest EventHandler, you can access the current URL by using ((HttpApplication)sender).Context.Request.Url.

and after some reading, you could redirect (((HttpApplication)sender).Context.Response.Redirect()) or rewrite (((HttpApplication)sender).Context.Response.RewritePath) the user to the target page (and the url folder name would be transported by a querystring parameter).

Hope this helps.

Best regards and as always: happy coding :),
Chris


这篇关于使用C#在asp.net中重写url以在页面初始化级别读取url以查找页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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