使用查询字符串重新路由URL或URL路由?

编程入门 行业动态 更新时间:2024-10-28 00:20:40
本文介绍了使用查询字符串重新路由URL或URL路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个页面Default.aspx,我想传递带有网址的查询字符串。 但我希望网址应该采用适当的格式。

受保护 void lnkForward_Click( object sender,EventArgs e) { try { string UserName = Session [ UserName]的ToString(); string url =〜/ Page2.aspx?UserName = + UserName; Response.Redirect(url, false ); } catch (例外) { 抛; } } < / pre > 现在它' s as as' http: // localhost:60160 / TestFolder / Page2.aspx?UserName = Jay'。 我希望它应该是applear int page2.aspx页面 as ' http:// localhost:60160 / TestFolder / Page2 / Jay'

解决方案

据我所知,你可以在MVC应用程序中找到这个功能。

protected void lnkForward_Click(object sender,EventArgs e) { try { string UserName = Session [UserName]。ToString(); string url =〜/ Page2 /+ UserName; Response.Redirect(url,false); } catch(例外) { throw; } } Web.config中的 <? xml version = 1.0 ? > <! - 有关如何配置ASP.NET应用程序的更多信息,请访问 go.microsoft/fwlink/?LinkId=169433 - > < 配置 > < configSections > < 部分 name = 重写器 requirePermission = false 类型 = Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,Intelligencia.UrlRewriter / > < / configSections > < system.web > < urlMappings 已启用 = true > < add url = 〜/ Static-页面 mappedUrl = 〜/ Static.aspx / > < / urlMappings > < httpModules > < add name = UrlRewriter type = Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter / > < / httpModules > < 编译 debug = true targetFramework = 4.0 / > < / system.web > < rewriter > < 重写 url = 〜/ Page /(.+)\" to = 〜/ Page2.aspx?用户=

1 / > < / rewriter > < / configuration > 将DDL添加到BIN Intelligencia.UrlRewriter.dll

I Have one page Default.aspx , i want to pass Query string with the url. But i want URL should come in a appropriate format.

protected void lnkForward_Click(object sender, EventArgs e) { try { string UserName=Session["UserName"].ToString(); string url = ~/Page2.aspx?UserName= + UserName; Response.Redirect(url, false); } catch (Exception) { throw; } }</pre> Now it's coming as ' localhost:60160/TestFolder/Page2.aspx?UserName=Jay '. I Want it should applear int the page2.aspx page as ' localhost:60160/TestFolder/Page2/Jay '

解决方案

According to me, you can find this functionality in MVC application.

protected void lnkForward_Click(object sender, EventArgs e) { try { string UserName=Session["UserName"].ToString(); string url = "~/Page2/" +UserName; Response.Redirect(url, false); } catch (Exception) { throw; } } in Web.config <?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit go.microsoft/fwlink/?LinkId=169433 --> <configuration> <configSections> <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/> </configSections> <system.web> <urlMappings enabled="true"> <add url="~/Static-Page" mappedUrl="~/Static.aspx" /> </urlMappings> <httpModules> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/> </httpModules> <compilation debug="true" targetFramework="4.0"/> </system.web> <rewriter> <rewrite url="~/Page/(.+)" to="~/Page2.aspx?User=

1"/> </rewriter> </configuration> Add to DDL to the BIN Intelligencia.UrlRewriter.dll

更多推荐

使用查询字符串重新路由URL或URL路由?

本文发布于:2023-11-13 01:21:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583016.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   字符串   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!