|
Thank you. Good thing I posted.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I don't really want to redirect.. I just didn't want it to try to load a view called 'export'. I wanted it to stay on the page it's on.
The code you posted seems to work just fine.
Thank you!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi all,
I am little new to MVC and WebApi, I am here trying to post values of html form to a HttpPost method of Web Api, here how I am using it
$("#btnSave").click(function () {
var defaultText = $("#defaultText").val();
var txtLanId = $("#txtLanId").val();
var txtLast = $("#txtLast").val();
var txtFirst = $("#txtFirst").val();
var txtEmployeeId = $("#txtEmployeeId").val();
var txtEmail = $("#txtEmail").val();
var dtFieldHireDate = $("#dtFieldHireDate").val();
var dtFieldRehireDate = $("#dtFieldRehireDate").val();
var lbxApplicationGroup = $("#lbxApplicationGroup").val();
var lbxReportPack = $("#lbxReportPack").val();
alert(dtFieldHireDate);
alert(dtFieldRehireDate);
alert(lbxApplicationGroup);
alert(lbxReportPack);
$.ajax({
url: "/api/EmployeeAPI",
type: "Post",
data: JSON.stringify([defaultText, txtLanId, txtLast, txtFirst, txtEmployeeId, txtEmail, dtFieldHireDate, dtFieldRehireDate, lbxApplicationGroup, lbxReportPack]),
contentType: 'application/json; charset=utf-8',
success: function (data) { },
error: function () { alert('error'); }
});
});
When I am trying to retrieve those values in the Web Api method, I am getting empty strings, I am not sure what's going wrong here, but any help is going to be very helpful, thanks in advance.
[System.Web.Http.HttpPost]
public string PostAction(System.Net.Http.Formatting.FormDataCollection form)
{
string retValues;
retValues = form.Get("txtLast") + form.Get("txtLanId");
return retValues;
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
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.
|
|
|
|