My Silverlight application needs one parameter, an integer. In my Html, I have written:
<param name="InitParameters" value="UserId=1" />
In code I am reading the parameters in:
foreach (KeyValuePair<string, string> pair in e.InitParams)
{
Resources.Add(pair.Key, pair.Value);
}
e.InitParams is always empty. Any ideas?
Because I'm passing in "InitParameters" instead of "InitParams". That's what I get for staring at my code for too long.
Related
Here's the RazorPages page I'm trying to make a link to:
#page "{ReportId:int}/{SicCode:alpha?}"
This works
<a asp-page="/ReportSics" asp-route-ReportId="3">rs1</a>
it produces
rs1
But this produces a blank href.
<a asp-page="/ReportSics" asp-route-ReportId="3" asp-route-SicCode="10">rss2</a>
That is: the tag helper works with one parameter but not with two.
Why?
Is it possible to make it work?
(I have another page with the same #page but with the second parameter not optional and it appears to be impossible to create a link to it.)
Furthermore, requesting Page/2/M works, but Page/2/12 returns 404. Why? (The second parameter is a string that can sometimes be a number, but it always treated as a string.)
From the learn.microsoft.com webpage asp-all-route-data offers the following:
asp-all-route-data
The asp-all-route-data attribute supports the creation of a dictionary of key-value pairs. The key is the parameter name, and the value is the parameter value.
In the following example, a dictionary is initialized and passed to a Razor view. Alternatively, the data could be passed in with your model.
#{
var parms = new Dictionary<string, string>
{
{ "speakerId", "11" },
{ "currentYear", "true" }
};
}
<a asp-route="speakerevalscurrent"
asp-all-route-data="parms">Speaker Evaluations</a>
The preceding code generates the following HTML:
Speaker Evaluations
Extension: From here the parameters can be accessed either explicitly in the parameter list of the method:
public IActionResult EvaluationCurrent(int speakerId, string currentYear)
or as a collection (See response: queryString:
public IActionResult EvaluationCurrent()
{
var queryString = this.Request.Query;
}
This works
Yes it works because it produces a route that is similar to this baseUrl/reportsics/?reportId=5
And the other produces a URL that is similar to this baseUrl/reportsics/?reportId=5&sicCode=678 and then it doesn't match your route definition. I think you should try this.
Experimental
asp-page="/reportSics/#myId/#sicCode
Though this would not be the right way to do what you're thinking. If you really want to change your URL structure, why not do url-rewrite?
Edit.
Form your recent comments, seems you want to pass many parameters in your action method and not targeting URL structure. Then I recommend you just
public IActionResult(string ReportId, string sicCode)
{
//......
}
//And the your URL target
<a asp-page="ReportSics" asp-route-ReportId="55" asp-route-sicCode="566" ></a>
And then it will match the route. I think you should remove that helper you placed after your #page definition and try it out if this is what you have already done and the problem persists.
It turns out that if a parameter has the constraint :alpha then it only works if the value being passed can not be parsed as an int or float.
I am trying to set up an azure function that would write into a blob only if a function is fulfilled. The blob is int he same location as the function, so I am trying to avoid providing a connection string and do this with bindings. I am currently using binding something like the following:
[Blob("folder/myFile.json", FileAccess.Write)]Stream writeBlob
With this binding, I can write into the JSON file using:
if (myCondition)
using (var writer = new StreamWriter(writeBlob))
writer.Write(myContent);
This works fine when the condition is true. However, when the condition is false, the file gets empty. Since I am not writing to the stream, I expected the file to stay untouched. Right now my workaround is to have another read binding to the same json and rewrite the file contents.
You can use dynamic binding in your case. See this post for more information:
How do I use Binder to perform dynamic bindings in my C# Function?
So basically you need to:
Add a IBinder binder parameter in your function definition.
When your condition is true, write your file:
if (myCondition)
{
var binding= new BlobAttribute(blobPath: "folder/myFile.json");
using (var writer = binder.Bind<TextWriter>(binding))
{
writer.Write(myContent);
}
}
I have an ASP.NET MVC app. My views use Razor. At the top of my CSHTML file, I have the following:
#functions
{
public static HtmlString IsSelectedCss(string name)
{
string selected = ""; // Need to get value of "t" from query string
HtmlString attribute = new HtmlString("");
if (selectedTab.Equals(name, StringComparison.InvariantCultureIgnoreCase))
{
attribute = new HtmlString("class=\"active\"");
}
return attribute;
}
}
I need this function to examine the query string. Specifically, I need to get the value of the "t" query string parameter. My challenge is, I cannot seem to figure out how to get access to the QueryString in this function.
How do I get the value of a query string parameter in a Razor function?
Thanks!
The query string can be gotten from below.
HttpContext.Current.Request.QueryString["t"]
You need to make your function non-static, since the querystring is part of the request.
You can then write
HttpContext.Request.Query["t"]
You should really be doing this in the controller and pushing it through the model. But if you insist, you can simply use:
<%= Request["t"] %>
But why not read it in your controller?!
So i'm having a weird issue with my service reference in my VS2010 project that i can't really figure out.
Any time i rebuild the soap service that the service reference is attached to i can no longer deserialize the data from one of the methods. All of the other methods work but one in particular just gets filled with null/default values instead of the correct values. I can confirm that the web service is still returning good data and looks to be in the correct format. Once i update the service reference it all works again until i rebuild.
When i go and look at the diff of the structure i see that the following files are now different:
Configuration.svcinfo
Configuration91.svcinfo
Reference.cs
Reference.svcmap
MyService.disco
MyService.wsdl
When i look in the wsdl it looks almost like the fields were re-ordered. But i don't see how that is possible.
Here is the header information for my web service
[WebService(Namespace = http://myservice/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[Policy("ServerPolicy")]
Anyone know why this is happening with each rebuild?
EDIT: Here is an example.
For example here is a random change that was made, this class was not changed but only recompiled:
Before:
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public string Userid {
get {
return this.useridField;
}
set {
this.useridField = value;
this.RaisePropertyChanged("Userid");
}
}
After:
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=2)]
public string Userid {
get {
return this.useridField;
}
set {
this.useridField = value;
this.RaisePropertyChanged("Userid");
}
}
Using Restlet 2.1 for Java EE, I am discovering an interesting problem with its ability to handle attributes.
Suppose you have code like the following:
cmp.getDefaultHost().attach("/testpath/{attr}",SomeServerResource.class);
and on your browser you provide the following URL:
http://localhost:8100/testpath/command
then, of course, the attr attribute gets set to "command".
Unfortunately, suppose you want the attribute to be something like command/test, as in the following URL:
http://localhost:8100/testpath/command/test
or if you want to dynamically add things with different levels, like:
http://localhost:800/testpath/command/test/subsystems/network/security
in both cases the attr attribute is still set to "command"!
Is there some way in a restlet application to make an attribute that can retain the "slash", so that one can, for example, make the attr attribute be set to "command/test"? I would like to be able to just grab everything after testpath and have the entire string be the attribute.
Is this possible? Someone please advise.
For the same case I usually change the type of the variable :
Route route = cmp.getDefaultHost().attach("/testpath/{attr}",SomeServerResource.class);
route.getTemplate().getVariables().get("attr") = new Variable(Variable.TYPE_URI_PATH);
You can do this by using url encoding.
I made the following attachment in my router:
router.attach("/test/{cmd}", TestResource.class);
My test resource class looks like this, with a little help from Apache Commons Codec URLCodec
#Override
protected Representation get() {
try {
String raw = ResourceWrapper.get(this, "cmd");
String decoded = new String(URLCodec.decodeUrl(raw.getBytes()));
return ResourceWrapper.wrap(raw + " " + decoded);
} catch(Exception e) { throw new RuntimeException(e); }
}
Note my resource wrapper class is simply utility methods. The get returns the string of the url param, and the wrap returns a StringRepresentation.
Now if I do something like this:
http://127.0.0.1/test/haha/awesome
I get a 404.
Instead, I do this:
http://127.0.0.1/test/haha%2fawesome
I have URLEncoded the folder path. This results in my browser saying:
haha%2fawesome haha/awesome
The first is the raw string, the second is the result. I don't know if this is suitable for your needs as it's a simplistic example, but as long as you URLEncode your attribute, you can decode it on the other end.