I have been trying hard to get a report from SSRS but seems like it is not supported in .Net Core. So I would like to know if is there a way to just download the report on browser in Asp .Net Core with parameters? All i need is to download it, no need to preview it with report view since there is no compatibility for this.
User clicks a button and parameters are sent through controller or razor page and just need a way to get report and download on browser
According to microsoft documentation, you need to first generate url according to your ssrs report & parameter as following...
https://servername/ReportServer_THESQLINSTANCE/Pages/ReportViewer.aspx?%2freportfolder%2freport+name+with+spaces&rs:Format=pdf
then pass this url to the following Controller Action....
public IActionResult GetReportingData(string url)
{
try
{
url = url.Replace("\n", "");
WebRequest request = WebRequest.Create(url);
NetworkCredential credentials = new NetworkCredential(#"**UserName*", "***Password***");
request.Credentials = credentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
return File(stream, "application/pdf");
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
this action will return/download a pdf file as you required.
Related
I don't know where to look or what to check but ask my question in title. Xamarin forms app works when sending json data over virtual phone instance but doesn't send data over physical no matter which platform i use , it is the same with iOS and Android.
static async Task phoneInfo()
{
string url = "http://blabla.com/api/blabla";
string sContentType = "application/json";
JObject jsonObject = new JObject();
jsonObject.Add("DeviceModel", DeviceInfo.Model);
jsonObject.Add("DeviceManufacturer", DeviceInfo.Manufacturer);
jsonObject.Add("DeviceName", DeviceInfo.Name);
jsonObject.Add("DeviceVersion", DeviceInfo.VersionString);
jsonObject.Add("DevicePlatform", DeviceInfo.Platform);
jsonObject.Add("DeviceIdiom", DeviceInfo.Idiom);
jsonObject.Add("DeviceType", DeviceInfo.DeviceType.ToString());
jsonObject.Add("AreaOne", DateTime.UtcNow.ToString());
jsonObject.Add("Deleted", false);
HttpClient oHttpClient = new HttpClient();
var oTaskPostAsync = await oHttpClient.PostAsync(url, new StringContent(jsonObject.ToString(), Encoding.UTF8, sContentType));
}
usage is simple like code. just put await phoneInfo(); where i want to take info.
i have accesswifistate and internet permission over Android and NSAppTransportSecurity for non https connection with iOS.
Any ideas where am i doing wrong?
I need to stream audio from my Web API. In standard HTML-5 audio src attribute is set to URI of the audio from WebAPI.
Problem is: Web API secured with Asp.Net Identity requires bearer token to be passed in the headers, however HTML AUDIO TAG doesn't allow us to do. I am finally left out with two alternatives:
Approach 1. Download the HTML using XHR request & play locally.
Approach 2. Pass headers via query string. So that we could inject the
token into OWIN pipeline at point of time during request processing.
First approach mentioned above is not viable, because if we download the audio locally we would miss out streaming features provided by Web API.
Could you please assist with approach-2 i.e. so that on Web API side we could read bearer token from URL & then initiate Asp.Net Identity Authentication?
Create this provider class
public class QueryStringOAuthBearerProvider : OAuthBearerAuthenticationProvider
{
public override Task RequestToken(OAuthRequestTokenContext context)
{
var value = context.Request.Query.Get("access_token");
if (!string.IsNullOrEmpty(value))
{
context.Token = value;
}
return Task.FromResult<object>(null);
}
}
Use it in Startup.cs
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
//app.UseOAuthBearerTokens(OAuthOptions); // old line
app.UseOAuthAuthorizationServer(OAuthOptions); // new line
// Enable the application to retrieve tokens from query string to authenticate users
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()
{
Provider = new QueryStringOAuthBearerProvider()
});
Now it will get token from url "..../?access_token=xxxxxxx" like that and try it to validate.
We are building a WinRT app which gets data from server which is Web API based & so it gives data in json and/or XML format.
When app user logs in for the first time using his credentials(username,password), the response that comes from server is a success bit & a TOKEN, which should be used in successive URL requests.
I am using httpclient for sending requests
using (HttpClient httpClient1 = new HttpClient())
{
string url = "http://example.com/abc/api/process1/GetLatestdata/10962f61-4865-4e7a-a121-3fdd968824b5?employeeid=6";
//The string 10962f61-4865-4e7a-a121-3fdd968824b5 is the token sent by the server
var response = await httpClient1.GetAsync(new Uri(url));
string content = await response.Content.ReadAsStringAsync();
}
Now the response that i get is with status code 401 "unauthorised".
And the xml i get in response is "Unauthorised User".
Is there anything i need to change in appManifest??
I've checked this, but cant we use httpclient without credentials??
Your Capabilities are enough. You don't even need Internet (Client) because it's included in Internet (Client & Server).
You do not have credentials for WinRT HttpClient, in your linked post they referr to System.Net.Http.HttpClientHandler.
Maybe you can use the HttpBaseProtocolFilter to add the credentials?
using (var httpFilter = new HttpBaseProtocolFilter())
{
using (var httpClient = new HttpClient(httpFilter))
{
httpFilter.ServerCredential...
}
}
I don't know your security mechanism, I'm using a HttpClient and my session-key is in a cookie. But I think your client code looks fine.
I got a Web API that performs a function and posts a JSON response back to a calling page.
This is standard Web API behaviour and works beautifully.
Now I want to modify the controller so that in addition to the post back the user is redirected back to the page on the calling web site where the result of the Web API call can be displayed (in JSON).
So basically I want to:
(1) Server side post back the results in JSON to a page and redirect to the same page from the Web API
(2) On the caller's site, I want to display the JSON that was posted back.
How do I do this?
I already tried for many hours ...
e.g.:
using (WebClient client = new WebClient())
{
client.Headers.Add("Content-Type", "text/json");
client.Headers.Add("Accept", "text/json");
try
{
ErrorText = client.UploadString(redirectURL, "POST", JsonConvert.SerializeObject(orderresponse));
Response.Redirect(redirectURL);
}
catch (WebException err)
{
ErrorText = err.Message; //Todo - write to logfile
}
}
Instead of doing the redirect on the server, instruct the client to do it by using the appropriate HTTP status code. For example:
public HttpResponseMessage Post(MyModel model)
{
// handle the post
MyResult result = ...;
// redirect
var response = Request.CreateResponse<MyResult>(HttpStatusCode.Moved, result);
response.Headers.Location = new Uri("http://www.yourdomain.com/redirectURI");
return response;
}
I was given an assignment to develop a very simple weather app in Android using the data given from
http://forecast.weather.gov/zipcity.php
This would be my first actual android app, my only other experience is watching/reading many tutorials on getting started.
To give some background information of the app, it simply needs to have one activity that is a
text field for the user to enter a city, state combination, or just a zip code. This then needs to be submitted to the website's (listed above) form.
After this has been submitted, my app needs to retrieve page sent in response and display it in a simple layout (possibly a listView of the days of the week).
My first question is, how would I go about submitting a text input to the above website's form? Would I have to know the name of the form's field to submit to it precisely?
In general, how should I start this process?
Edited version:
Using this code:
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://forecast.weather.gov/zipcity.php?inputstring=04419");
HttpResponse httpResp;
try {
httpResp = httpClient.execute(post);
StatusLine status = httpResp.getStatusLine();
Toast.makeText(getApplicationContext(), status.getStatusCode(), Toast.LENGTH_SHORT).show();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I'm getting a:
10-26 15:29:56.686: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
error in the debug view. Is this error related? Is my use of toast reasonable for testing if this http interaction is successful?
When you want to see what a post request in passing use Firefox + tamperdata, that way you can look at how to use the webservice.
I took a look at it, I searched for "33129" and when you enter text on the left hand box to start a search it simply pases 2 parameters:
inputstring = "33129"
Go2 = "Go"
That would be one way to do it, on the other hand, once the request is finished it transforms it into another request, thats more specific. You can search by city state or zip, not both.
If you request with a zip you get redirected to:
http://forecast.weather.gov/MapClick.php?CityName=Miami&state=FL&site=MFL&lat=25.77&lon=-80.2
So there is probably a redirection going on there.
You are going to have to take a close look at how to work with this.
Now, to do a post request in android use a name value pair like this.
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("inputstring","33129));
Ramp's answer shows the rest.
Also, ALL comunication should be done on a thread that is not the main UI thread or you will get a ANR error.
When I checked out your URL, I entered city and state.This is the URL it generates in HTTP POST :
http://forecast.weather.gov/MapClick.php?CityName=Edison&state=NJ&site=PHI&textField1=40.5288&textField2=-74.3693
So your will do a HTTP POST with the CityName and state URL parameters. It will be something like this if you use apache HttpClient in your android program :
( It should be OK to use HTTP GET too I guess)
HttpPost post = new HttpPost(url);//construct url with cityName and State
HttpResponse httpResp = httpClient.execute(post);
StatusLine status = httpResp.getStatusLine();
Hope this helps.
Something like this:
HttpClient hc = new DefaultHttpClient();
List<NameValuePair> l = new ArrayList<NameValuePair>(6);
l.add(new BasicNameValuePair("fieldname", "fieldvalue"));
//More fields...
HttpPost pr = new HttpPost(TheURL);
pr.setEntity(new UrlEncodedFormEntity(l, "the-proper-encoding"));
HttpResponse Resp = hc.execute(pr);
if(Resp.getStatusLine().getStatusCode() != 200)
//Fail...