English 中文(简体)
允许在 Web. config 中使用查询字符串的位置路径
原标题:Allow location path with querystring in web.config

我的网络里有这个 配置

  <location path="ChangePassword.aspx">
     <system.web>
       <authorization>
         <allow users="*"/>
       </authorization>
     </system.web>   </location>

问题是,在访问网页工作时,我需要允许用查询字符串加入该页面,但这样做行不通:

  • ChangePassword.aspx?mode=
  • ChangePassword.aspx?userid=xx&mode=

如何做到这一点? 参数将总是有动态值, 当然, 我无法在 Web. config 中输入硬码 ID 。

EDIT 更好地了解问题

目的 = 未登录用户必须能够访问 ChangePassword.aspx 页面及其收到的任何查询字符串 。

对于未登录用户的问题 :

  • They can access ChangePassword.aspx
  • They can NOT access ChangePassword.aspx?parameter=value
最佳回答

如果用户可以访问页面, 他们可以在路径中添加查询字符串 。

授权机制仅在文件位置上运行 - - 您无法使它在查询字符串参数上运行 。

如果您想要根据参数改变页面行为, 您应该在页面代码中这样做 。

您可以很容易地访问页面上的查询字符串参数 :

Request.QueryString["UserId"]
问题回答

The problem is not in the web.config: your settings regarding the tag are correct. The problem is the link

ChangePassword.aspx?Userid=xx&mode=

不允许您页面正确路由的字符是“<% amp; ”。

确保它使用正确的 Xml 编码来写入( 它将以 & amp; 替换所有 & amp; 字符 ) 。

这应很好地发挥作用:

ChangePassword.aspx?Userid=xx&amp;mode=

或者你可以使用

系统. Web. HttpUpitity. HtmlEnccode (yourUrl) 系统;

我希望它有用 ;)





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签