This question already has an answer here:
ASP.NET page POST only access
(1 answer)
Closed 3 years ago.
I am using asp.net web form.I am giving my page's url(www.domainname.Test.aspx) to client.I want client should send data by post method only,how to do that?
Which is best content type for this?
answered here https://stackoverflow.com/a/32326741/2122217
on Page_Load
if (!string.Equals(Request.HttpMethod, "POST"))
{
Response.StatusCode = 405;
Response.End();
}
Related
This question already has answers here:
Output log using FtpWebRequest
(2 answers)
Closed 3 years ago.
Is there a way to override web Request or any other thing to log request/response for every web request(FTP or SFTP) we make.
I want to log it in DB thats why I want to override somehow.
Please note: I am asking solution for asp.net Core only.
Consider using RestSharp for .net core and log the response.Content which contains the raw response received on the wire, and then you could do like suggested here to get the request body before sending it:
request.Parameters.Where(p => p.Type == ParameterType.RequestBody).FirstOrDefault();
This question already has answers here:
How to get "Host:" header from HttpContext (asp.net)
(4 answers)
Closed 8 years ago.
I want to get datas from an html file on my asp webserver, in Javascript to get actual host we can use the following:
~/mydatas.php
It gives on localhost: "http://localhost/mydatas.php"
I want the same thing but in C# can you help me?
Thanks you.
You could also search in stackoverflow and you will find a lot of answered question which had the same problematic than you. Like this one
Hopes it will help you !
Edit : You can use
HttpContext.Current.Request.Url.AbsoluteUri
It will give you the URL of your web page.
I've already try
HttpContext.Current.Request.Url.Host
which gives on localhost
:\windows\system32\inetsrv\localhost
...
This question already has answers here:
How do I get the referrer URL in an ASP.NET MVC action?
(4 answers)
Closed 8 years ago.
I have asp.net mvc 4 application, where I need to do some action when I came from HomeController ActionResult DoSmth(). How can I check this?
I use
Request.UrlRefferer
To do this.
You can use the following
var controller = (string)this.RouteData.Values["controller"];
var action = (string)this.RouteData.Values["action"];
Not sure if relevant, but if you want to make sure that action is rendered only from your code you can use attribute [ChildActtion].
Otherwise check this answer: ASP.NET MVC - Check if request comes from another action
This question already has answers here:
How to get Url Hash (#) from server side
(6 answers)
Closed 9 years ago.
How to get the value after # in the following url:
www.google.com/trian/test#dummyvalue
I am using ASP.NET and C#
A web browser won't pass this value back to the server. So in a typical scenario with a user on their computer accessing your website. The "fragment" portion of the url won't be supplied to the server. Therefore, your asp.net code can not access it. If you change your code to put this data in the querystring, then you can access it server side from asp.net.
This question already has an answer here:
Get URL of Referer page in ASP.NET
(1 answer)
Closed 8 years ago.
I'm using web api.My question is: I have to check from where call is coming in Global.asax(Application_AcquireRequestState) because I have to restrict some calls which are coming from unknown urls for the purpose of web api security.
You can use Request.UserHostAddress to get the IP address from which the call is coming and Request.UrlReferrer to get the URL that linked to the current URL.