Sen*_*nsa 6 asp.net query-string
如何读取aspx页面中的任何字符串.
例如:http://foo.com/bike stand
我想在指定的aspx页面中读取/获取字符串.预期页面字符串是自行车站
预期页面是getstring.aspx
在这里,我想读取字符串并重定向到指定的页面.
注意:我喜欢在ASP.Net(不使用MVC)中执行此操作
为此,您可以使用IIS URL 重写模块。安装后,您可以在 Web.ConfigSystem.Webserver节点中创建一条重写 url 的规则,以便可以在代码隐藏中将字符串作为查询字符串进行处理。
<rewrite>
<rules>
<rule name="getString" stopProcessing="true">
<match url="^([a-z0-9- /]+)$" ignoreCase="true"/>
<action type="Rewrite" url="getstring.aspx?string={R:1}"/>
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
然后你可以简单地通过以下方式获取字符串值:
string getString = Request.QueryString["string"];
Run Code Online (Sandbox Code Playgroud)
但是,如果存在不需要访问的其他页面,则会产生问题getstring.aspx,因为现在每个请求都发送到 getstring.aspx。也许最好使用前缀,以便您可以将请求 URL 识别为具有字符串的 URL。
http://foo.com/getstring/bike stand
<match url="^getstring/([a-z0-9- /]+)$" ignoreCase="true"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
212 次 |
| 最近记录: |