jeudi 24 septembre 2015

Closing a Web Page

Here is part of my code:

if(s.equals("Fluff")){
             Desktop c=Desktop.getDesktop();
             c.browse(new URI("https://www.youtube.com/watch?v=_9kdZ07BCFQ"));
         }

I'd like for the user to be able to type 'stop' to kill the web page. I have looked online, but all I am seeing is window.close(). I tried it, but it didn't work - I think because I am using Desktop instead of window. How would I go about doing this?

I'm new to coding, so the solution may be obvious, I just don't see it. Explain thoroughly - I'd like to learn, not copy/paste.




Wget http auth incorrect username and password combination

I'm at a total loss as to why I'm getting Authorization failed messages when I try to perform basic HTTP auth using wget on an internal webpage.

I've been using this wget command to pull a csv file from an internal webpage for around 4 months on a daily basis without issues.

wget --user username --password "password" http://ift.tt/1MLEcmm

The site is not SSL and does prompt for credentials when visiting it with a web browser. I've verified that the credentials I am using in the call work in a browser to download the CSV.

I've tried modifying the wget command by adding the following additional flags:

--auth-no-challenge

I also changed the --username to --http-user and the password to --http-passwd but those options do not work either.

When I attempt the connection with wget I get a 401 Unauthorized Authorization failed message.

The site is sharepoint,and unless something recently changed this month with IIS that disables calls from wget, I cannot figure out for the life of me what changed...

Any help would be appreciated.




Calling a web api from another web api, after 110 seconds waiting my action fires again. Any ideas how to avoid that?

I have a Web Api 2 it is calling another Web Api. The scenario is simple, I am uploading a file from Angular.Js. then Angular calls a web api, this web api calls another web api. The last web api takes 2 minutes to respond, so when the first web api times out (after 110 seconds), it is fired again. I have reproduced this issue in a clean environment and it is something that comes with Web Api. The problem it is I don't know how to tell my web api, I need more time to receive the answer from my request, any ideas? This is the first web api action, it doesn't help a lot but...

    [HttpPost]
    [MultipartContentValidator]
    [ActionName("uploadfile")]      
    // POST /api/documents/uploadfile?folderId={folderId}&assetId={assetId}
    public async Task<HttpResponseMessage> UploadFile(int folderId, int assetId)
    {
        IExternalWebApiCaller _caller = new ExternalWebApiCaller();
        //## If it is not multipart, we throw it away
        if (!Request.Content.IsMimeMultipartContent("form-data"))
        {
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }

        //## Getting the juice in memory instead of the harddrive
        var provider = await Request.Content.ReadAsMultipartAsync<InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider());

        //## We get access to the data
        NameValueCollection formData = provider.FormData;

        //## It will access to the files
        IList<HttpContent> files = provider.Files;

        //## Reading a file as bytearray and creating the model
        //## with the filename and stuff...if any
        if (files != null)
        {
            HttpContent filetobeuploaded = files[0];
            byte[] filebytearray = await filetobeuploaded.ReadAsByteArrayAsync();

            DocumentUploadViewModel model = new DocumentUploadViewModel();
            model.AssetId = assetId;
            model.FolderId = folderId;
            model.Data = filebytearray;
            model.Filename = filetobeuploaded.Headers.ContentDisposition.FileName.Replace("\"", "");

            return await _caller.CallWebApiHttpResponseMessage("api/document/uploadfile", HttpMethod.Post, null, model, GetHeaders());
        }
        else
        {
            //## Something fail (file with no content), so we kick this out
            throw new HttpResponseException(HttpStatusCode.NoContent);
        }
    }




A Simple utility to monitor web application performance

My system setup is like: Application A takes requests from outside world and communicates with the backend REST apis. REST api also communicates with mysql database.

My requirement is to have a tool from which I can just monitor the resource usage and may be the performance of the web server. I want to have graphs for the resource usage which means I need historical data otherwise I would have just used the windows task manager to see the resource usage.

This means I do not need any load generator(that will be done by the Application A) just a resource monitor.

I googled and found tools like appdynamics, Nagios, munin but not sure if they are what I need. I haven't done performance testing earlier so there's lot of confusion.

Just looking for some guidance.

Thanks




Unexpected behavior in ASP.NET VS2013 on handling Server.Transfer and Setting IsPostBack

In VS2013 using Framework 4.5, I experienced what I consider to be unexpected behavior using server.transfer's from button clicks as I traversed from page to page. To illustrate here, I started a new VS2013 Web Site in Visual Basic using the ASP.NET Web Forms Site Template.

I added three new web Forms as Test1.aspx, Test2.aspx and Test3.aspx, each using the auto-generated Site.Master. The page code for each is:

Test1.aspx:

hfTest0 (Coming  In): <asp:Label ID="lbl1" runat="server" Text=""></asp:Label>
<br />
hfTest1 (Coming In): <asp:Label ID="lbl3" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btnTest" runat="server" Text="GoTo Test2" />
<br />
hfTest0 (After Load): <asp:Label ID="lbl2" runat="server" Text=""></asp:Label>
<br />
hfTest2 (After Load): <asp:Label ID="lbl4" runat="server" Text=""></asp:Label>

Test2.aspx:

hfTest0 (Coming  In): <asp:Label ID="lbl1" runat="server" Text=""></asp:Label>
<br />
hfTest1 (Coming In): <asp:Label ID="lbl3" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btnTest" runat="server" Text="GoTo Test3" />
<br />
hfTest0 (After Load): <asp:Label ID="lbl2" runat="server" Text=""></asp:Label>
<br />
hfTest2 (After Load): <asp:Label ID="lbl4" runat="server" Text=""></asp:Label>

Test3.aspx:

hfTest0 (Coming  In): <asp:Label ID="lbl1" runat="server" Text=""></asp:Label>
<br />
hfTest1 (Coming In): <asp:Label ID="lbl3" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btnTest" runat="server" Text="GoTo Test1" />
<br />
hfTest0 (After Load): <asp:Label ID="lbl2" runat="server" Text=""></asp:Label>
<br />
hfTest2 (After Load): <asp:Label ID="lbl4" runat="server" Text=""></asp:Label>

To support the above references to the hidden fields of hfTest0 and hfTest2, I added these fields to the Site.Master Page as:

Site.Master:

<asp:HiddenField ID="hfTest0" runat="server" Value=""/> 
<asp:HiddenField ID="hfTest1" runat="server" Value=""/>

The above two fields are examples of what I am trying to achieve in terms of maintaing state when transferring from page to page.

For the Code-Behind in the three test pages I included the following blocks of code in the Sub for the Load Event as:

Test1.aspx.vb

        If IsPostBack Then

            Exit Sub

        End If

        If Me.PreviousPage Is Nothing Then

            lbl1.Text = ""

            lbl3.Text = ""

            CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

            CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "one"
        Else

            lbl1.Text = CType(Me.PreviousPage.Master.FindControl("hfTest0"), HiddenField).Value

            lbl3.Text = CType(Me.PreviousPage.Master.FindControl("hfTest1"), HiddenField).Value

            If CType(Me.PreviousPage.Master.FindControl("hfTest0"), HiddenField).Value = "Active" Then

                CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

                CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "ONE"
            Else
                CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

                CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "one"
            End If
        End If

    lbl2.Text = CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value

    lbl4.Text = CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value

Test2.aspx.vb

        If IsPostBack Then

            Exit Sub

        End If

        If Me.PreviousPage Is Nothing Then

            lbl1.Text = ""

            lbl3.Text = ""

            CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

            CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "two"
        Else

            lbl1.Text = CType(Me.PreviousPage.Master.FindControl("hfTest0"), HiddenField).Value

            lbl3.Text = CType(Me.PreviousPage.Master.FindControl("hfTest1"), HiddenField).Value

            If CType(Me.PreviousPage.Master.FindControl("hfTest0"), HiddenField).Value = "Active" Then

                CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

                CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "TWO"
            Else
                CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

                CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "two"
            End If
        End If

    lbl2.Text = CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value

    lbl4.Text = CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value

Test3.aspx.vb

        If IsPostBack Then

            Exit Sub

        End If

        If Me.PreviousPage Is Nothing Then

            lbl1.Text = ""

            lbl3.Text = ""

            CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

            CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "three"
        Else

            lbl1.Text = CType(Me.PreviousPage.Master.FindControl("hfTest0"), HiddenField).Value

            lbl3.Text = CType(Me.PreviousPage.Master.FindControl("hfTest1"), HiddenField).Value

            If CType(Me.PreviousPage.Master.FindControl("hfTest0"), HiddenField).Value = "Active" Then

                CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

                CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "THREE"
            Else
                CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value = "Active"

                CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value = "three"
            End If
        End If

    lbl2.Text = CType(Me.Page.Master.FindControl("hfTest0"), HiddenField).Value

    lbl4.Text = CType(Me.Page.Master.FindControl("hfTest1"), HiddenField).Value

For the three test pages code-behind btnTest Click Events, I added the following: single lines:

Test1.aspx.vb Server.Transfer("Test2.aspx", True)

Test2.aspx.vb Server.Transfer("Test3.aspx", True)

Test3.aspx.vb Server.Transfer("Test1.aspx", True)

This makes for a testing loop wherein the page Test1 transfers to Test2 which transfers to Test3 which transfers back to Test1 all using the Button Click with the Server.Transfer.

When I start the web site at Test1, the IsPostBack is initially false and Me.PreviousPage Is Nothing as expected and displays the expected values in the page body as:

hfTest0 (Coming In):
hfTest1 (Coming In): 

btnTest BUTTON HERE with Text = "GoTo Test2"

hfTest0 (After Load): Active
hfTest2 (After Load): one

Upon clicking the btnTest on Test1, it again fires the Load Event of Test1 with IsPostBack now equal to TRUE and Me.PreviousPage Is Nothing as expected. Then it fires the load event of Test2 with IsPostBack set to FALSE and the Me.PreviousPage set to Test1 as expected and displays the expected values in the page body as:

hfTest0 (Coming In): Active
hfTest1 (Coming In): one

btnTest BUTTON HERE with Text = "GoTo Test3"

hfTest0 (After Load): Active
hfTest2 (After Load): TWO 

Upon clicking the btnTest on Test2, it fires the Load Event of Test2 with IsPostBack again equal to FALSE. I WOULD HAVE EXPECTED IT TO BE TRUE. Also the Me.PreviousPage Is Nothing. Because of the Unexpected conditions above, the resulting page display is:

hfTest0 (Coming In):
hfTest1 (Coming In): 

btnTest BUTTON HERE with Text = "GoTo Test3"

hfTest0 (After Load): Active
hfTest2 (After Load): two

Upon clicking the btnTest with it's Text Value of "GoTo Test3", it fired the Test2 Load with the IsPostback = TRUE and Me.PreviousPage of Nothing. Then it fired the Load of Test3 with the IsPostBack equal to FALSE and the Me.PreviousPage equal to Test2. The page values displayed as:

hfTest0 (Coming In): Active
hfTest1 (Coming In): two

btnTest BUTTON HERE with Text = "GoTo Test1"

hfTest0 (After Load): Active
hfTest2 (After Load): THREE

This pattern repeats itself. The desired passing of parameters is not achieved. For the page on which the btnTest is first clicked, the IsPostBack is not set to True necessitating another button click to go to the next page, but without the desired setting of the hidden fields in the Site.Master.


HERE's THE THING ABOUT THE BEHAVIOR I EXPECTED


When I recreate FROM SCRATCH this website using VS2012 using Visual Basic and the exact code above, it transfers faithfully from page to page on the first clicks setting the hidden fields as desired. I think the main problem here is that on the first transfer to another page, the IsPostBack settings work the expected way, but not for the next subsequent transfer.

Furthermore, when I run the website created in VS2013 in VS2012, it exhibits the same unexpected and undesired behavior.

Thank you for reading my long explanation. Am I missing something basic here?

Any help will be much appreciated.




Pushing SQL-File from controller to webclient

I got an controller with an 32bit atmel cpu, no floating point, which runs an custom linux deriviat.

This controller provides a webpage over http. This http server is written in c++ and lua. Ethernetcontroller is an Davicom DM9000A 16bit.

There's an SQLite3 DB on the controller which I'd like to sent to the client if client requests this file via http.

Page is up, client has connection and everything is fine. But now the last step, sending the SQL File from controller to client is a problem.

How could I archive this?




ODATA and CRUD operations with MVC Web Api

I need to create a service (currently with ASP.NET Web Api) that is taking data from SQL database and exposes them using OData protocol. I'm extremely new to OData and Web Api. The problem is i don't know how to perform crud operations - i've looked through some samples available online but my case is a little bit more complicated (or maybe not, hard to say). I'm using entity framework. Sometimes i need to do the "GET" with quering table directly but do "POST" with stored procedure. The biggest problem i have is limitation in parameters amount. As i understand i can have only one. This is rather an issue in my case:

  public class ProjectsController : ODataController
{
    [EnableQuery]
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    public IQueryable<GetProjects_Result> Get(string key)
    {
        var context = new OPMLVSQL001Entities();
        IQueryable<GetProjects_Result> results = context.GetProjects(key);
        return results;
    }

    [EnableQuery]
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    public GetProject_Result Get(int projectId, string loginName)
    {
        var context = new OPMLVSQL001Entities();
        GetProject_Result result = context.GetProject(projectId, loginName).FirstOrDefault();
        return result;
    }

that code won't work - just to get all projects, i need to pass a login parameter. to get one entity i need to use different method - and i have to pass two parameters. which i don't know how to do in odata (i thought of a hack - passing json table in the only parameter i can use).

So is there a way to use more than one parameter?

i also have to implement a "create" method - an entity is being created with stored procedure again. What is the best way to follow in this case?

one way probably is to add, Project entity to the project and do post like this:

        [EnableQuery]
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    public HttpResponseMessage Post(Project project)
    {

    }

but what if i have some logic in dbo.CreateProject([bunch of parameters]) that i need to run along and for that reason i'd like to run the stored proc. use values from projects to initialize dbo.CreateProjects parameters? I really don't know what's the best way to follow.