解析查询字符串在ASP.NET MVC3一个地方 [英] Parse Query String at one place in ASP.NET MVC3

查看:102
本文介绍了解析查询字符串在ASP.NET MVC3一个地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要捕捉的查询字符串code?code =可能被追加到各个环节,这环节将在其他网站上的广告中使用。

I want to capture the query string code "?CODE=" which could be append to various links and this links will be used in the advertisements on other websites.

www.TestProject.com/Home?$c$c=ASCD

www.TestProject.com/FAQ?$c$c=ASCD2

www.TestProject.com/Tips?$c$c=ASCD3

因此​​,当用户点击这个链接上的code将被捕获并保存在cookie中。如果网站上的用户注册则code将用他的注册ID链接。

So when the user clicks on this link the code will be captured and saved in a cookie. And if the user registers on the site then the code will be linked with his registration ID.

我已经写了code在静态辅助类捕获的URL。我对这个方法的调用所有的控制器/操作方法。

I have written the code in a static helper class to capture the URL. I make a call to this method from all the controller/Action Methods.

我想知道,如果这是正确的做法或者我应该调用此方法在Global.asax中的Application_BeginRequest()方法。

I wanted to know if this is the correct approach or should i call this method in Global.asax Application_BeginRequest() Method.

推荐答案

我将创建一个自定义的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.actionfilterattribute%28v=vs.108%29.aspx\"相对=nofollow> ActionFilterAttribute

I would create a custom ActionFilterAttribute.

您可以用它来标记某些动作,控制器,也可以为所有在您的网站

You can use it to mark certain actions, controllers, or you can register it for all the actions in your website

protected void Application_Start()
{
    //...
    GlobalFilters.Filters.Add(new MvcProfilerGlobalAttribute());
}

这篇关于解析查询字符串在ASP.NET MVC3一个地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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