使用查询字符串重新路由URL或URL路由? [英] URL Rewitting or URL Routing with Query String?

查看:125
本文介绍了使用查询字符串重新路由URL或URL路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面Default.aspx,我想传递带有网址的查询字符串。

但我希望网址应该采用适当的格式。



 受保护  void  lnkForward_Click( object  sender,EventArgs e)
{
try
{
< span class =code-keyword> 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应用程序的更多信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
- >

< 配置 >
< configSections >
< 部分 name = 重写器 < span class =code-attribute> 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 >
< span class =code-keyword>< 重写 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 ' http://localhost:60160/TestFolder/Page2.aspx?UserName=Jay '.

I Want it should applear int the page2.aspx page as ' http://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
 http://go.microsoft.com/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路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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