Request.UrlReferrer在IE8及更低版本中为null [英] Request.UrlReferrer is null in IE8 and lower

查看:107
本文介绍了Request.UrlReferrer在IE8及更低版本中为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个管理员给出的任务,做一些没有身体可以篡改我们网站的研究,如果有人试图篡改URL只是显示消息或页面崩溃。



我试过很多方法,但最后我找到了HttpContext.Current.Request.UrlReferrer。此属性是readonly和浏览器相关。每当有人试图直接在url中更改时,属性将变为null,我们可以相应地编写一些代码。



这在所有浏览器上成功运行,除了我发现IE 8或更低版本。

我试图克服这个问题一个多星期但没有解决方案。



最后我发现了一个解决方案,我将在答案中发布。



如果有人有任何更好的解决方案然后请在我的代码项目博客中分享。



谢谢。

解决方案

As我告诉我很久以后我点击我的解决方案我只是用代码详细说明了这些东西。



当用document.location.href或window打开一个新窗口时。在IE8或更低版本中打开,Request.UrlReferrer为null,不在IE9或Firefox或Chrome中。



解决方案是



你曾经使用过像

document.location.href =/ Roles / Index;



将以下函数复制并粘贴到js文件中并调用该函数。



RedirectURL(/ Roles / Index);



函数RedirectURL(url){

var a = document.createElement(a);

if(a.click){

// HTML5浏览器和IE支持上的click(),早期FF没有。

a.setAttribute(href,url);

a.style .display =none;

document.body.appendChild(a);

a.click();

} else {

//然而,早期的FF可以使用这种通常的方法

//其中IE无法使用安全链接。

window.location.href = url;

}

}



希望以上解决方案能解决问题。

I have a task given by Manager that do some research that no body can tampering our site, if someone try to tamper the URL just show a message or page crash.

I tried many ways but finally I found HttpContext.Current.Request.UrlReferrer. This property is readonly and browser dependent. Whenever somebody is trying to change directly in the url then property is going to null and we can write some code accordingly.

This is successfully run on all the browser except the IE 8 or below what I found.
I tried to overcome this issue more than a week but no resolution.

Finally I found one solution in my mind which going to post in Answer.

If anybody has any better solution then please share it in my code project blog.

Thank you.

解决方案

As I told after long RND I click on solution on my mind I just elaborate the things with code.

When open a new window with document.location.href or window.open then in IE8 or lower, Request.UrlReferrer is null which is not in IE9 or Firefox or Chrome.

The solution is

Where ever you used like
document.location.href = "/Roles/Index";

Just copy and paste the below function in js file and call that function.

RedirectURL("/Roles/Index");

function RedirectURL(url) {
var a = document.createElement("a");
if (a.click) {
// HTML5 browsers and IE support click() on , early FF does not.
a.setAttribute("href", url);
a.style.display = "none";
document.body.appendChild(a);
a.click();
} else {
// Early FF can, however, use this usual method
// where IE cannot with secure links.
window.location.href = url;
}
}

Hopefully the above solution will resolve the issue.


这篇关于Request.UrlReferrer在IE8及更低版本中为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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