开发者

How to find user has opened a new tab in MVC .net? how to differentiate between simple click request and tab request on client /server side?

I want to differentiate between a new tab or new window request and simple request (i.e page opening in the same tab) on server or client side in MVC .net?

actually, we are nor using content placeholders in the layout page. we have div in it and child pages are loaded in it.so child aspx pages don't have Master page specified for them. so when a new tab is opened for page, our master page is not attached to it, so all look and feel is lost. now I want to identify a tab request @server side so as to send the required page with layout page.

I tried using Request.refferer to find the presence of master page, but the absolute URI is not always same for Firefox and IE

Current Scen开发者_Go百科ario => 1) Simple request : controller => Action => returns with Master page

2) Request generated when the user right clicks on the link and opens new tab: controller=>ActionName => returns view without master page attached


The HTTP header fields have a fair amount of information in them, but whether or not the request originated from a new window is not included. Based on your question it sounds like you are using a lot of client side code for content retrieval and rendering - Ajax.

Assuming that is the case your best bet is looking at the nonstandard HTTP request field X-Requested-With:

mainly used to identify Ajax requests. Most JavaScript frameworks send this header with value of XMLHttpRequest

In ASP.NET MVC you can use the Request.IsAjaxRequest extension method to poke at this field. In this manner if a link is opened in a new window you can return the full page Site.Master and all. When the request is your expected behavior you'll know because it is an Ajax request.

That said, I'd recommend working on the way that you are rendering content and look up information on progressive enhancement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜