Search code examples
c#silverlight-4.0query-stringwcf-ria-services

Query string not recognized


I have to following problem:
When I go to my site:

http://localhost:9684/MainPage.aspx?UserID=VABRAEIAUgBBAEUARQBBAFAAUQBBAD0A

It has to check if there is a query string (UserID) and if there is a query string it has to save it in the variable sIngelogdID I'm useing the following code for this:

string sIngelogdID = System.Web.HttpContext.Current.Request.QueryString["UserID"]; 

However when I look at it in debug mode it says that there are 0 query strings, so it doesn't see UserID as a query string.
This is written in a WCF-RIA-service.
Does anybody have an idea how to achieve this?
Thanks in advance!

EDIT:
The UserID comes from a different Silverlight 4 application. At this application the user logs in after that the login details (the Id of the user that logged in) has to be passed to another Silverlight 4 application. If there is another way (better) way to achieve this, also please let me know.


Solution

  • You may use InitParams instead for sending values.

    Firstly capture the querystring from the aspx page which hosted your silverlight application, In MainPage.aspx.cs

    public string GetUserId()
    {
        return HttpContext.Current.Request.QueryString["UserId"];
    }
    

    Now under MainPage.aspx you need to insert code as below under body=> form=> find param and add

    <param name="InitParams" value="param1=<%= GetUserId() %>" />
    

    Now capture the param1 in the App.xaml.cs Application_Startup method as

            if (e.InitParams.ContainsKey("param1"))
            {
                userId = e.InitParams["param1"].ToString();
            }
    

    Hope this helps