|
Hello everybody,
Is there a way to set multiple groups in Active Directory ?
For example :
DirectoryEntry grp;
grp = aduser.Children.Find($"CN={group},OU=Gruppen,OU=FIR", "group")
grp = aduser.Children.Add(group, "group");
|
|
|
|
|
I have a POST method with [FromBody] attribute. I tried to call the same from PostMan. But everytime Postman gives 404 error. The Web Api is not hitting at all. Following is my source code:
[HttpPost]
[Route("api/CustomerService")]
public HttpResponseMessage GetServiceChats([FromBody]string to, string from)
{ }
What I have done is, I added the parameters by Selecting Body-->raw-->JSON options and type the parameters as below:
{
"to" : "919191919191",
"from" : "90909090900"
}
What could be the probable reason? If the same I attached in URL without the FromBody attribute, it works. Please provide any suggestions.
|
|
|
|
|
The [FromBody] attribute is used to read a single simple value from the request body:
Parameter Binding in ASP.NET Web API - ASP.NET 4.x | Microsoft Docs[^]
Given your signature, the from parameter needs to be a query-string parameter, and the request body needs to be simply:
"90909090900"
If you want the API to match the request you've shown, use a model to represent the parameters:
public class ServiceChatsModel
{
public string To { get; set; }
public string From { get; set; }
}
[HttpPost]
[Route("api/CustomerService")]
public HttpResponseMessage GetServiceChats(ServiceChatsModel model)
{
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes. Thank you Richard. I have done that in the meanwhile,and got it worked.Thank you. Worked both in Postman and Fiddler.
|
|
|
|
|
|
i able to call Get Method.
but fail to call PUT, DELETE Method.
i added in webconfig.
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<remove name="OPTIONSVerbHandler"/>
<remove name="TRACEVerbHandler"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
</system.webServer>
below is my controller code :
[HttpPut]
[Route("api/PutEmployeeGenderEmpCode/{_EmpCode}")]
public void PutEmployeeGenderEmpCode(string _EmpCode)
{
string TempValue = "1";
SqlConnection Conn = new SqlConnection(ConnectionString);
CheckConnectionStatus(Conn);
Conn.Open();
string SQLCommand = "UPDATE [dbo].[M_EMP_MASTER] ";
SQLCommand = SQLCommand + "SET ";
SQLCommand = SQLCommand + "[EMP_GENDER] = '" + TempValue + "' ";
SQLCommand = SQLCommand + "WHERE [EMP_CODE] = '" + _EmpCode + "'";
var cmd2 = new SqlCommand(SQLCommand, Conn);
cmd2.ExecuteNonQuery();
Conn.Close();
Conn.Dispose();
}
when call : this is the error show :
http://localhost:44322/api/PutEmployeeGenderEmpCode/502
General
----------
request URL: https:
Request Method: GET
Status Code: 405
Remote Address: [::1]:44322
Referrer Policy: no-referrer-when-downgrade
Response Header
----------------
allow: PUT
cache-control: no-cache
content-length: 92
content-type: application/xml; charset=utf-8
date: Mon, 18 May 2020 08:39:04 GMT
expires: -1
pragma: no-cache
server: Microsoft-IIS/10.0
status: 405
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET
x-sourcefiles: =?UTF-8?B?QzpcMjAyMFxDQlMyMDAwNCAtIE1PQklMRSAtIFRFU1RcV2ViQVBJXzNcV2ViQVBJM1xXZWJBUEkzXGFwaVxQdXRFbXBsb3llZUdlbmRlckVtcENvZGVcNTAy?=
Request Header
---------------
:authority: localhost:44322
:method: GET
:path: /api/PutEmployeeGenderEmpCode/502
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*
<error>
<message>
The requested resource does not support http method 'GET'.
Thanks in advance..
|
|
|
|
|
feelblue87 wrote: Request Method: GET
You've issued a GET request instead of a PUT request. The error is with your code to call the API, which you haven't shown.
feelblue87 wrote:
string SQLCommand = "UPDATE [dbo].[M_EMP_MASTER] ";
SQLCommand = SQLCommand + "SET ";
SQLCommand = SQLCommand + "[EMP_GENDER] = '" + TempValue + "' ";
SQLCommand = SQLCommand + "WHERE [EMP_CODE] = '" + _EmpCode + "'"; Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
[HttpPut]
[Route("api/PutEmployeeGenderEmpCode/{_EmpCode}")]
public void PutEmployeeGenderEmpCode(string _EmpCode)
{
const string SQLCommand = "UPDATE [dbo].[M_EMP_MASTER] SET [EMP_GENDER] = @EmpGender WHERE [EMP_CODE] = @EmpCode";
string TempValue = "1";
using (var conn = new SqlConnection(ConnectionString))
using (var cmd2 = new SqlCommand(SQLCommand, conn))
{
cmd2.Parameters.AddWithValue("@EmpGender", TempValue);
cmd2.Parameters.AddWithValue("@EmpCode", _EmpCode);
CheckConnectionStatus(conn);
conn.Open();
cmd2.ExecuteNonQuery();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi. I am bigginer.
I want to add button and create event in asp.net.
and how to link sql server
please help
|
|
|
|
|
Get a book and work through the examples or work through one of the many articles here. Once you have learned the basics feel free to ask for help with specific issues you will come across.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Bonjour,
Je débute le développement et l’utilisation des web services.
Ce web service sera développé dans un environnement ASP.NET et doit permettre d'accéder à une base des données oracle 11g distante pour récupérer des données de certaines tables.
Après sera appelé et utilisé dans une application web mcv développée sous visuel studio 2012.
Comment faire afin de développer et utiliser ce web service ?
Merci.
|
|
|
|
|
Bonjour,
Je débute le développement et l’utilisation des web services.
Ce web service sera développé dans un environnement ASP.NET et doit permettre d'accéder à une base des données oracle 11g distante pour récupérer des données de certaines tables.
Après sera appelé et utilisé dans une application web mcv développée sous visuel studio 2012.
Comment faire afin de développer et utiliser ce web service ?
Merci.
|
|
|
|
|
Hello I am working on a project where I must be able to display information recorded via a form in a datatable without going through the registration of the database, I suppose that it will be to record the information in a list to browse it and display the information in the datatable. but I really don't know how to do it. and is it already possible?
|
|
|
|
|
You have already posted this in QA:
Insert data into list from form[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In our web app, as expected, the DbContext for our data is injected with DI.
It is registered with this extension method (the one that take a Func<> factory method):
public static IServiceCollection AddScoped<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory) where TService : class;
Now every now and then, due to maintenance task in our UAT servers, the Database is offline for a little while.
If that ever happen while someone try to connect to the DB, anyservice that need that DbContext fail with the same exception. Regardless whether the DB is back online or not.
We need to restart the app to fix that.
Now I wonder.. is there a way to fix that? (A way that doesn't involve restarting our app!)
[EDIT] Solved
It was DI for Startup.Configure() which prevented the application from running.
DI itself is fine and as expected!
modified 12-May-20 1:20am.
|
|
|
|
|
That doesn't sound right. Each request should result in a new instance of the DbContext , which should make a new connection. The failure of a previous connection shouldn't affect it.
What does the implementation factory look like, and what's the exception?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
my bad....
it was DI for Startup.Configure() which was bringing the application down....
so DI is fine, it's just the app was broken!
|
|
|
|
|
Hi all, how do I set a route ( or attribute or whatever ) so I can call this method which is present in a net core api controller ? assume my controller is called MyController - I've googled endlessly and can't find a simple answer
I would like to be able to access it something like this
myipaddress:myportnumber/MyController/1
public ActionResult<Actuator> GetAValue(int id)
{
return businessLayer.GetAValue(id);
}
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
There's an example on the Microsoft docs site which is close to what you want:
Routing to controller actions in ASP.NET Core | Microsoft Docs[^]
[Route("[controller]")]
[ApiController]
public class MyController : ControllerBase
{
[HttpGet("{id:int}")]
public ActionResult<Actuator> GetAValue(int id)
{
...
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard thanks for the suggestion but I'm still getting a 404 - v weird
Edit
Apologies Richard it does work - thanks again
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
modified 6-May-20 5:37am.
|
|
|
|
|
I use this for API JSON Calls. But you can tweak into other uses as well
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class MyController : ControllerBase
{
[HttpGet("GetWarehousesKv/{vendorId}")]
public async Task<List<KeyValue>> GetWarehousesKv(string vendorId)
{
return await myRepository.GetWarehousesKv(vendorId);<br />
}
}
And I call it like this.
Notice the controller route prefix api ?
and notice the controller name My
https://domain.com/api/my/GetWarehousesKV/500689
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hi thanks for that I have it sorted now
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Cool!
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Suppose I have a web project that is made up of a Web API, a bunch of HTML files, and some Javascript files. Is it possible to provide security to my project files with nothing more than a login page which posts a user's credentials to the Web API which then queries the database to check if the user exists?
If it's possible, how would I control things like redirect users to a certain page upon successful login or better yet prevent users from accessing any page other than the login page if they're not logged in?
modified 1-May-20 2:59am.
|
|
|
|
|
|
Hi, thanks for replying. I don't know if you understood my questions above but let me rephrase. What I'm asking is if my web project consists of only HTML files, some Javascript files, a Web API, and nothing else. Would it be possible to provide security to my web project?
Remember that I did not mention MVC or Web Form. If it is possible to secure my project without using MVC controllers or web form, how would I authorize users after successful logins?
modified 1-May-20 8:46am.
|
|
|
|