网址引荐来源 [英] Url Referer

查看:79
本文介绍了网址引荐来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个使用c#在.net 3.5中开发的基于Web的应用程序.

在我的应用程序中,我试图不允许匿名用户篡改URL,所以我使用以下代码.

Hi all,

I have a web based application developed in .net 3.5 with c#.

In my application I''m trying to not to allow the anonymous users from the tampering the url, so I''m using the following code.

if(Session["empid"]==null || Session["empid"]!=null)
{
if(Request.UrlReferrer==null)
{
//redirect to some page
}
}



我已将上面的代码放在母版页的page_init中.
如果用户没有登录就可以正常工作,当用户登录并且再次单击页面中的某些超链接时,该用户将被注销.



I have placed the above code in the page_init of masterpage.
When the user comes without loggin in it works perfectly, when the user logs in and if clicks on some hyperlink in a page again the user is being logged out.

Is there any alternative to this problem?

推荐答案

将此配置放入webconfig文件中,它将帮助您保护免受匿名用户的侵害

路径="admin"是Web表单的文件夹

Place this config into webconfig file it will help you to protect from anonymous users

Path ="admin" is a folder of web form

<location path="admin">
    <system.web>
      <authorization>
        <allow roles="admin"/>
        <deny users="*"/>
      </authorization>
    </system.web>


我无法完全理解您要传达的内容.

但是我对您的代码有一些建议.

I cannot understand completely what you are trying to convey.

But I have some advise for your code.

if(Session["empid"]==null || Session["empid"]!=null)



您已经为NULL Not NULL编写了代码,那么如果要传递任何条件,为什么需要指定条件.



You have written code for If it is NULL or Not NULL then why there is need to specify condition if you want to pass in any of criteria.

if(Request.UrlReferrer==null)


UrlReferrer 的值是URL 的字符串,从中重定向当前页面.

因此,如果它为null,则它必须是初始请求.

因此,如果是第一个请求,您的代码将在这种情况下运行.

如果您有一些意见,请进一步研究您的代码,如果没有成功,请放入运行不正常的代码段.

如果有帮助,请 投票 接受答案 .


Value of UrlReferrer is the string of the URL from which the current page is redirected.

So If it is null then It must be the initial request.

So your code will run in the case if it is first request.

If you got some points then investigate your code further, and if not succeed then put your code snippets which is running undesirably.

Please vote and Accept Answer if it Helped.


Basically when we use Request.UrlReferrer and the user tampers in the address bar the page can be sent to a custom page.

but when the same code is used when clicking on a hyperlink the Request.urlreferer is becoming null and teh page is moved to the custom page again.

how to restrict this.


这篇关于网址引荐来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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