|
The FormDataCollection expects an x-www-form-urlencoded submission. You're submitting a JSON-serialized array of strings.
If you don't want to change the API method, you'll need to change the script that calls it:
$("#btnSave").click(function () {
var postData = {
defaultText = $("#defaultText").val(),
txtLanId = $("#txtLanId").val(),
txtLast = $("#txtLast").val(),
txtFirst = $("#txtFirst").val(),
txtEmployeeId = $("#txtEmployeeId").val(),
txtEmail = $("#txtEmail").val(),
dtFieldHireDate = $("#dtFieldHireDate").val(),
dtFieldRehireDate = $("#dtFieldRehireDate").val(),
lbxApplicationGroup = $("#lbxApplicationGroup").val(),
lbxReportPack = $("#lbxReportPack").val()
};
console.log("POST", postData);
$.ajax({
type: "POST",
url: "/api/EmployeeAPI",
data: postData,
success: function(data) { console.log("Success", data); },
error: function() { alert("Error"); }
});
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I did this but still the values are not being posted at the Post Method of Web Api, do I need to make any change in the Web Api method as well? Please let me know please my friend?
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Check the "network" tab in the browser's developer tools to see what's actually being sent to the server.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
how to use querry string with various methods
|
|
|
|
|
Depends on the methods. Perhaps you could edit your question and explain exactly what you are trying to do.
|
|
|
|
|
HttpRequest.QueryString Property (System.Web)[^]
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
If you look at the Request object in your method (Of course it is a web application) , you will be able to see the QueryString property there and you can retrieve the values from it.
|
|
|
|
|
I need to be able to lock down the URL of a small application so that the client cannot use the URL with multiple devices. I need to be able to assign some type of generated key/license so that if the client purchases 1 URL they can only use that URL on 1 device. This has nothing to do with sessions and or restricting an employee by the device.
Can something like this be done? Can a unique key be added at the end of the URL and save into the device cookies or something like that
Any directions?
|
|
|
|
|
Unique keys can be added to URLs, can be sent via headers, can be stored on the server-side so that when a request comes by the URL is served otherwise a redirect is issued.
There are several ways at doing this, how do you want to do that, is a bit confusing. The thing is, your requirement needs a license, or a process that tells the system whether a user can access this information or not.
ASP.NET doesn't care about purchase systems, licensing, access etc. You have to manage that and tell ASP.NET, how to configure itself to allow/disallow access to certain parts of the application. That said, this is entirely possible, please be more specific or show some code so that we may guide you further.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
If you read the comments to that answer, you'll see that it's retrieving the server's MAC address. As are almost all the other answers on that thread.
If the client is not on the same subnet as the server, there is no way to retrieve the MAC address of the client from the server. There have occasionally been hacks which exploited security vulnerabilities on the client to allow you to retrieve it, but those are fixed almost as soon as they're found.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please help me... I am stuck up with http post using http request.
I have an asp.net applicaton which is hosted locally in IIS(http:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Test Web Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
function showImage() {
alert('hi');
}
</script>
</head>
<body>
<form id="imageForm" name="imageForm" method="post" action="Default.aspx" >
<input type="text" name="showImage" value="false" />
<input type="submit" name="refresh" value="submit" onclick="showImage();" />
</form>
</body>
</html>
My Default.aspx.cs ;
protected void Page_Load(Object Source, EventArgs E)
{
}
I have a separate c# application which tries to simulate the button click of "refresh" via http post to Default.aspx, here is the code;
string url = "http://localhost/TestWebPage/Default.aspx";
string postDataStr = "showImage=true";
postDataStr += "&refresh=submit";
byte[] postData = Encoding.ASCII.GetBytes(postDataStr);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postData.Length;
req.Proxy = WebRequest.DefaultWebProxy;
using (var reqStream = req.GetRequestStream())
{
reqStream.Write(postData, 0, postData.Length);
}
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.Default);
string pageContent = reader.ReadToEnd();
string status = ((HttpWebResponse)response).StatusDescription;
reader.Close();
responseStream.Close();
response.Close();
My aspx page is already opened in a chrome browser. When the above code is executed, I want the javascript alert in the showImage() function to be displayed in the Default.aspx page in the same browser window itself.
Unfortunately its not happening now... am I missing anything? or is there any good approach to simulate the button click using separate c#?
Please guide.
|
|
|
|
|
You already posted this in the C# forum. Please post in one place only.
|
|
|
|
|
Hi,am developing an asp.net in vs2008 and want to successfully get the jQury library running within vs8.
Through googling,I have come to realize that I need to download and install a hotfix for vs8 called KB946581. I have however tirelessly tried to find where to download this fix but failed. Can someone please give a legitimate source? My efforts so far are as follows:
<script type = "text/javascript" src="/jQuery/jquery-1.7.1.min.js"></script>
<script src="/jQuery/jquery-1.7.1.min-vsdoc.js" type="text/javascript"></script>
<script type = "text/javascript" src="/jQuery/jquery.nivo.slider.pack.js"></script>
I plan on using the Nivo slider plugin to effect some image animations on my home page.
Hope some can give a better reliable outlay of how to get jQuery runing in vs2008.
|
|
|
|
|
What's wrong with what you have? Getting jQuery working is just a matter of including the right js file as you are doing. Make sure the path is valid, however you should use something like Page.ResolveUrl for webforms or Url.Content for MVC to turn a virtual path (~/jQuery/...) into a working path.
|
|
|
|
|
Hi,I succeeded in getting jQuery 1.2.6 library running in visual studio 2008.Thanks for the guide.However when I try using library version 1.7.1 it does not work.Could there be another special hotfix for vs8 prof. edition to support this library version or what could I be missing??
In my trials testing I noticed that;
This works perfect:
<script type = "text/javascript" src="<%:ResolveUrl("~/scripts/jquery-1.2.6.js")%>"></script>
<script type ="text/javascript" src="<%: ResolveUrl("~/scripts/jquery-1.2.6-vsdoc.js")%>"></script>
But when I try this below -- It fails...why???
<script type = "text/javascript" src="<%:ResolveUrl("~/scripts/jquery-1.7.1.js")%>"></script>
<script type ="text/javascript" src="<%: ResolveUrl("~/scripts/jquery-1.7.1-vsdoc.js")%>"></script>
Please highlight explicitly....
|
|
|
|
|
What do you mean by "fails"?
Is it not loading the script? If so, check that you've got the correct path and filename.
Is it generating a client-side error? If so, you'll need to give us the details of the error, and tell us which browser you're using.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Okay,once I have referenced the js scripts,then try check if there is any intellisense using the jquery selector $(),I get nothing however with version 1.2.6 of the library,it shows intellisense.
I have no client side script errors so far. Am using
Google chrome Version 59.0.3071.86 .
|
|
|
|
|
So it's not that jQuery isn't working; it's just that you're not getting intellisense?
Try this article: How to fix Visual Studio 2008 Intellisense for JQuery 1.6.1[^] - it says 1.6.1, but it probably applies to 1.7 as well.
If it still doesn't work, then you'll either need to upgrade to a more recent version of Visual Studio, or fall back to using the jQuery documentation[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
code taken from this area https://www.codeproject.com/Articles/1005485/RESTful-Day-sharp-Security-in-Web-APIs-Basic#_Toc423441907
[GET("allproducts")]
[GET("all")]
public HttpResponseMessage Get()
{
}
[GET("productid/{id?}")]
[GET("particularproduct/{id?}")]
[GET("myproduct/{id:range(1, 3)}")]
public HttpResponseMessage Get(int id)
{
}
[POST("Create")]
[POST("Register")]
public int Post([FromBody] ProductEntity productEntity)
{
}
[PUT("Update/productid/{id}")]
[PUT("Modify/productid/{id}")]
public bool Put(int id, [FromBody] ProductEntity productEntity)
{
}
[DELETE("remove/productid/{id}")]
[DELETE("clear/productid/{id}")]
[PUT("delete/productid/{id}")]
public bool Delete(int id)
{
}
1) in what kind of scenario people use multiple http verbs for single action because it create multiple route for single action which may confuse people.......should the the below approach is good or not ?
[GET("productid/{id?}")]
[GET("particularproduct/{id?}")]
[GET("myproduct/{id:range(1, 3)}")]
public HttpResponseMessage Get(int id)
{}
2)PUT and DELETE is different verbs. how one can use different verbs for single action....is it right approach.
[DELETE("remove/productid/{id}")]
[DELETE("clear/productid/{id}")]
[PUT("delete/productid/{id}")]
public bool Delete(int id)
{
if (id > 0)
return _productServices.DeleteProduct(id);
return false;
}
the person who wrote this article he is codeproject MVP it means he has good command over technology then how he can follow a wrong approach ?
any idea?
please discuss in details. thanks
|
|
|
|
|
Please post your question in the forum at the end of the article.
|
|
|
|
|
Rathan than thinking that multiple urls are used to call the same method, think of it that multiple API methods can all be served by the same function. So there are various REST methods you can use that will result in a product being deleted, so those various methods may as well be handled by the same code method.
However I don't think the GET example is a particularly good way of doing things. If I want to get a product using REST I'll call Product/id. Being able to use that url or "particularproduct" doesn't seem to be adding any value, just having two urls that do the same thing.
As suggested though ask your question on the article, this is just my personal opinion and the author may well have a good answer that renders my opinion invalid.
|
|
|
|
|
yes i did it but the author "akhil mittal" did not answer still.
|
|
|
|
|
i am learning web api. just gone through few article and found attribute routing can be done different way. i visited these articles
https://www.codeproject.com/Articles/774807/Attribute-Routing-in-ASP-NET-MVC-WebAPI http://www.c-sharpcorner.com/UploadFile/b1df45/web-api-route-and-route-prefix-part-2/ https://www.codeproject.com/Articles/999691/RESTful-Day-sharp-Custom-URL-Re-Writing-Routing-us
[RoutePrefix("Movie")]
public class HomeController : Controller
{
[Route]
public ActionResult Index()
{
ViewBag.Message = "You are in Home Index";
return View();
}
[Route("~/NewRoute/About")]
public ActionResult About()
{
ViewBag.Message = "You successfully reached NEWRoute/About route";
return View();
}
}
in above example the author use Route attribute to define route for action.
see this one again
[GET("productid/{id?}")]
public HttpResponseMessage Get(int id)
{
var product = _productServices.GetProductById(id);
if (product != null)
return Request.CreateResponse(HttpStatusCode.OK, product);
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "No product found for this id");
}
here author do not use route attribute rather use http verbs to define route.
so tell me which approach is right ?
another question that by attribute routine we can give different name to action then when one should use action name attribute to give different name to action?
when we can change action name by attribute routing then why should one use action name attribute to give different name to action?
please clarify my two points. thanks
|
|
|
|
|
hi all.
I add in a loop many user controls and i see them on screen, but when a click is performed in one of them, all of the fires the click event.
I'm new in asp.net, so if you see coding horrors be nice.
Thanks
here i add the controls
protected void Page_Load(object sender, EventArgs e)
{
AddProgressBarForPN(3, "rev123", "pndesc123", "pn123");
AddProgressBarForPN(2, "rev12", "pndesc12", "pn12");
AddProgressBarForPN(1, "rev1", "pndesc1", "pn1");
}
void prog_ProgressBarBttnClicked(string stempID,string pn)
{
support.Logs(stempID +" "+pn, "prog_ProgressBarBttnClicked", false);
}
protected void cloneBttn_Click(object sender, EventArgs e)
{
}
private void AddProgressBarForPN(int step,string rev,string pn_desc,string pn)
{
prog = (ProgressBarControl)LoadControl("~/ProgressBarControl.ascx");
prog.ProgressBarBttnClicked += prog_ProgressBarBttnClicked;
prog.Step = step;
prog.Revision = rev;
prog.PN_Description = pn_desc;
prog.ClientName = pn_desc;
prog.PN = pn;
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell1 = new HtmlTableCell();
cell1.Controls.Add(prog);
row.Cells.Add(cell1);
mainTable.Rows.Add(row);
and this is the control html
var idd;
function getID(oObject) {
idd = oObject.id;
var hdnfldVariable = document.getElementById('hdnfldVariable');
__doPostBack(idd);
}
table, th, td
{
color:darkblue;
margin-top:-15px;
}
<asp:hiddenfield id="hdnfldVariable" runat="server">
<asp:table style="width:100%;margin-top:15px" id="mainTable" runat="server">
<asp:tablerow>
<asp:tablecell>
PN: | <%=this.PN %> | / | Client: | <%=this.ClientName %> | / | Description: | <%=this.PN_Description %> | / | Rev: | <%=this.Revision %> |
<%-- onclick="StepClicked(this)"--%>
1
Collect files
2
Software preparation
3
Debug
4
Validation
5
Release
and control code behind
public delegate void ProgreesBarButton(string stepID,string PN);
public event ProgreesBarButton ProgressBarBttnClicked = delegate { };
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.GetPostBackEventReference(this, string.Empty);
var arg = Request.Form["__EVENTTARGET"];
if(arg != null)
{
string progBttnID = arg.ToString();
ProgressBarBttnClicked(progBttnID,PN);
}
}
public string ClientName{ get; set; }
public string PN_Description{ get; set; }
public string PN{ get; set; }
public string Revision{ get; set; }
public string step1 { get; set; }
public string step2 { get; set; }
public string step3 { get; set; }
public string step4 { get; set; }
public string step5 { get; set; }
int step;
public int Step
{
get { return step;}
set
{
step = value;
for (int i = 1; i <= step; i++)
{
switch (i)
{
case 1:
step1 = "active";
break;
case 2:
step2 = "active";
break;
case 3:
step3 = "active";
break;
case 4:
step4 = "active";
break;
case 5:
step5 = "active";
break;
}
}
for (int i = step+1; i <= 5; i++)
{ switch (i)
{
case 1:
step1 = "";
break;
case 2:
step2 = "";
break;
case 3:
step3 = "";
break;
case 4:
step4 = "";
break;
case 5:
step5 = "";
break;
}
}
}
}
public void StepClicked(string stepid)
{
ProgressBarBttnClicked(stepid, PN);
}
modified 8-Jun-17 9:09am.
|
|
|
|