本文介绍了使用查询字符串重新路由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路由?
发布评论