Using MVC 3 Asp.Net, I would like to add a default Query String on any method in a controller.
Using the following code I get an error at line ... QueryString.Add():
Collection is read only.
Any idea how to fix it, or do you know a better way how to append a query string to method of a controller? Please post a sample of code thanks.
public class HomeController : Controller
{
protected override void Initialize(RequestContext requestContext)
{
// Add the User's ID if is not present in the request
string user = requestContext.HttpContext.Request.QueryString["UniqueStudentReference"];
if (user == null)
{
string userId = Various.GetGivenNameUser();
System.Web.HttpContext.Current.Request.QueryString.Add("UniqueStudentReference", userId);
}
base.Initialize(requestContext);
}
...