Get entire URL from Request.Headers["Referer"]? - c#

I'm using the TableFilter javascript library in a .NET 6.0 project (C#). When I've filtered out some data I can click on an item to edit it. After I've edited it I would like to return to the previous page, with the same filters applied.
When I come to the Edit page I can use Request.Headers["Referer"].ToString() to catch the referring URL. But it always only contains the URL up until the last bit, which tells TableFilter which filters to apply.
An example. If this is the URL when I've filtered:
https://localhost:7290/foo?a=2361ded1-b9bc-4007-840b-e5ddb864002b#%7B%22col_1%22%3A%7B%22flt%22%3A%22Monitor%22%7D%7D
Request.Headers["Referer"].ToString() just contains everyting up until the #:
https://localhost:7290/foo?a=2361ded1-b9bc-4007-840b-e5ddb864002b
Anyone know of the way for me to catch the last part as well?

Related

Saving SSRS multi select parameter value with wildcard

I have searched and searched and have not been able to find the answer to this. I'm no stranger to SSRS, .Net (c# and vb.net), SQL, etc...been in it for years. I currently have a multi-select report parameter that is populated by a dataset in my report. There are hundreds of entries, so I built it to be driven by a wildcard character in a preceding parameter. Everything works fine right now. My question is this: is it possible to enter a wildcard value, select one (or more) of the filtered values and then store that/those value(s) on selection so that a user can go back and enter another wildcard value and select from a newly filtered list? (Basically, remember what has been selected in the overall dataset before report execution and create some sort of comma-separated list as the final parameter value to be passed to the report) I realize this may be better served in a web app w/a reportviewer control, but I'm trying to avoid deviating from the native SSRS server if possible. Thanks in advance!
The way I might approach this (not actually done it but the theory sounds ok)
Have 2 parameters for user input, your current one and a hidden one called say #filter (visible) and #filterHistory (this is the hidden one)
Have a textbox (formatted like button) with something like "Refine" as the text. Set the action to call your report again but set the #filterHistory to be something like #filterHistory & ", " & #filter. Basically we keep appending the last user input to the history.
Then your report would filter based on both parameters. You'll have to do some parsing of the delimited parameter now to split it out into the constituent parts but you get the idea.
I've no time to build a test report but hopefully that will point you in the right direction. If it doesn't help or work then comment and I'll see if I can knock up a quick example.

Find all elements by xpath attribute (aria-required = true) .//*[#aria-required='true']

I'm trying to get a list of IwebElements that contain the attribute aria-required. Reason why I'm trying to get this list, is so that i can check if all required fields are necessary for the user to fill out, before he can continue to the next page.
So far after 2 days of searching I'm still convinced that it shouldn't be that hard. I'm using the expression:
".//*[#aria-required='true']"
From my research that would mean that it will search for ALL the elements starting from the root of my webdriver.
[TestMethod]
public void CreateProjectWithoutRequiredFields()
{
GoToProjectPage();
tracking = CM.GoToNewlyCreatedFrameAfterClickButton("ftbNew", tracking, theDriver);
CM.Wait(2000);
bool succesSave = false;
CM.LogToFile("Create project whitout required fields", tracking);
foreach (IWebElement e in theDriver.FindElements(By.XPath(".//*[#aria-required='true']")))
{
FillDataInNewProjectPage();
e.Clear();
CM.GetDynamicElementById("btnSave", theDriver).Click();
try
{
CM.GetDynamicElementById("titel", theDriver).Click();
}
catch (Exception)
{
succesSave = true;
NUnit.Framework.Assert.IsFalse(succesSave, "The page is saved with succes, without entering text in the following required fields : " + e.GetAttribute("id").ToString());
}
CM.Wait(1000);
}
}
I will try to explain what i did here:
First i went to a overview page with all my existing projects. On this page i clicked the ftbNew button to create a new project. The driver is automatically switch to the correct frame (i now the right frame is selected because i used this line on other page's.)
then the line
foreach (IWebElement e in theDriver.FindElements(By.XPath(".//*[#aria-required='true']")))
{
should normaly find a the elements in my driver with an attribute "aria-required='true'"
Then it would fill in the page with data, clear the first element that is found from its data en try to save it.
if the element titel is found on the page, than we are still on the same page en the save action wasn't successful ( <- so this is good)
so next we again overwrite every field on the page and clear this time the second element that is found.
en so on...
What I'm guessing, that xpath has difficulty finding the 'old' aria-required attribute... When i try to validate my expression using firebug and other xpath checkers, the aria-required attribute isn't always present. Sometimes it finds the input field sometimes it doesn't.
source code page
As you can see in the firebug console not all attributes are loaded, account-manager has a aria-required attribute, but project leader doesn't. If i inspect the element again, but this time click project leader. The attribute will be loaded. Very strange....
Extra info: I am using frame's and i know a lot can go wrong if you are situated in the wrong frame, but i am sure that he is looking in the correct frame. Especially because i can't find the elements using firebug with the above expression. If i change my expression to .//input, it will find the elements but also selects input fields that aren't required.
In advance i want to thank everybody that want to look into my problem :)
Adriaan
Based on your description of the behavior on the page, you cannot rely on the aria-required attribute to indicate a required field. I think that you should go back to the developers of the site to ask them to give you a reliable handle. It may be as simple as looking for the "*" as the last character of the label associated with the input field, but that's kind of annoying to have to deal with.
As an aside, you should consider catching a more specific exception for your success case. Right now, if ANY exception happens, you'll declare success, but that may not be what you really want to do.

How do you implement an auto-updating search box so that the names appear as you type?

I have an index page where a table is generated with rows of information from the DB.
I have successfully integrated Tom Dykstra's method of adding a search box using this tutorial: http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
How would I implement behavior that shows names that already exist as they are being typed in the search box, or automatically update the rows in the table as something is typed into the search box?
I am using MVC 5 with EF6.
Thank you!
I would use the jQuery UI Autocomplete widget with a remote source for the data.
https://jqueryui.com/autocomplete/#remote
For the remote source either write a new action on your controller that returns JSON, or a WebAPI action to do the same, and in there do a query against your database to find matching results for the users query
The best way to do this would be to use AngularJs. We can't give you a full example of this, I can only give you an approach. Angular is very powerful and as well it is client side which speeds up you application very much. See the example shown in the docs of angular.
You can use the filtering on everything (tables, divs, list etc.)
https://docs.angularjs.org/api/ng/filter/filter
Here is an example of how to implement AngularJS in Asp.Net MVC.
http://www.codeproject.com/Articles/806029/Getting-started-with-AngularJS-and-ASP-NET-MVC-Par
Here is also an JSFiddle example on how it can look like:
http://jsfiddle.net/mikeeconroy/QL28C/1/
<tr ng-repeat="product in products | filter:search | orderBy:'name'">
<td>{{product.name}}</td>
<td>{{product.category}}</td>
</tr>
This code snippet would do the filtering for you

Umbraco Architecture with query string parameters for document

I have a client web app that I've been asked to make some updates to. I have a small number of development hours to work within so a redesign of the system is not an option at this time.
The app was written using classic asp with logic to pull certain content dynamically from a custom database and to write back certain user actions to the same custom database. There is an admin area for viewing these logged user actions.
At some point in time portions of the web app were migrated to use Umbraco 4 for the cms. I've been tasked with migrating some additional content, that is still being pulled from the original custom database, into the context of the CMS.
The content in question is structured so that the content node's document type points to a special masterpage. The master page has codebehind logic that checks for a query string parameter and uses that parameter to query the database for content specific to that parameter. In then populates one specific section on the page with that content.
The logic also uses the query string parameter when writing user actions back to the custom database.
I need to maintain the url syntax and behavior of writing user actions back to the custom database but move the displayed content specific to that parameter into the CMS somewhere. Where should I place this content in the CMS and how can I access it from those pages via the query string parameter?
Url Examples:
/site_home/Node1/Node2/Node3/
/site_home/Node1/Node2/Node3/?partner=partner1
/site_home/Node1/Node2/Node3/?partner=partner2
/site_home/Node1/Node2/Node3/Review/
/site_home/Node1/Node2/Node3/Review/?partner=partner1
/site_home/Node1/Node2/Node3/Review/?partner=partner2
/site_home/Node1/Node2/Node3/Checkout/
/site_home/Node1/Node2/Node3/Checkout/?partner=partner1
/site_home/Node1/Node2/Node3/Checkout/?partner=partner2
If you can provide a bit clearer explanation of what you are trying to accomplish, I am sure that I can assist you further. However, the code below and link to the discussion from which I pulled it may help get you on the path. Give me some feedback or edit your question and I will edit my answer to assist.
#{
if(!string.IsNullOrEmpty(Request.QueryString["query"]))
{
int result= 0;
if(Int32.TryParse(HttpContext.Current.Request.QueryString["query"].ToString(), out result))
{
umbraco.MacroEngines.DynamicNode node = new umbraco.MacroEngines.DynamicNode(result);
<h1> #node.Name </h1>
}
else
{
<h2>No query found</h2>
}
}
}
Umbraco Forums - Render Node content from querystring

Can I pass a .net Object via querystring?

I stucked at a condition , where i need to share values between the pages. I want to share value from Codebehind via little or no javascript. I already have a question here on SO , but using JS. Still did'nt got any result so another approach i am asking.
So I want to know can i pass any .net object in query string. SO that i can unbox it on other end conveniently.
Update
Or is there any JavaScript approach, by passing it to windows modal dialog. or something like that.
What I am doing
What i was doing is that on my parent page load. I am extracting the properties from my class that has values fetched from db. and put it in a Session["mySession"]. Some thing like this.
Session["mySession"] = myClass.myStatus which is List<int>;
Now on one my event that checkbox click event from client side, i am opening a popup. and on its page load, extracting the list and filling the checkbox list on the child page.
Now from here user can modify its selection and close this page. Close is done via a button called save , on which i am iterating through the checked items and again sending it in Session["mySession"].
But the problem is here , when ever i again click on radio button to view the updated values , it displays the previous one. That is , If my total count of list is 3 from the db, and after modification it is 1. After reopening it still displays 3 instead of 1.
Yes, you could but you would have to serialize that value so that it could be encoded as a string. I think a much better approach would be to put the object in session rather than on the URL.
I would so something like this.
var stringNumbers = intNumbers.Select(i => i.ToString()).ToArray();
var qsValue = string.Join(",", stringNumbers);
Request.Redirect("Page.aspx?numbers=" + sqValue);
Keep in mind that if there are too many numbers the query string is not the best option. Also remember that anyone can see the query string so if this data needs to be secure do not use the query string. Keep in mind the suggestions of other posters.
Note
If you are using .NET 4 you can simplify the above code:
var qsValue = string.Join(",", intNumbers);
Make the object serializable and store it in an out-of-process session.
All pages on your web application will then be able to access the object.
you could serialize it and make it printable but you shouldn't
really, you shouldn't
The specification does not dictate a minimum or maximum URL length, but implementation varies by browser and version. For example, Internet Explorer does not support URLs that have more than 2083 characters.[6][7] There is no limit on the number of parameters in a URL; only the raw (as opposed to URL encoded) character length of the URL matters. Web servers may also impose limits on the length of the query string, depending on how the URL and query string is stored. If the URL is too long, the web server fails with the 414 Request-URI Too Long HTTP status code.
I would probably use a cookie to store the object.

Categories

Resources